Configure iptables firewall for CentOS
Yesterday, I helped my friend configure the CentOS server. At the beginning, I shut down the firewall for convenience of testing. Then I needed to configure the firewall. I found several firewall rules on the Internet with errors, later I found that the post by the blogger was not serious, and there were too many character errors. below is the configuration process of the available firewall rules I prepared:
Modify iptables-config
First, modify a configuration item in the iptables-config file.
$ Vi/etc/sysconfig/iptables-config
Change IPTABLES_MODULES = "ip_conntrack_ftp" in the last line of the file to # IPTABLES_MODULES = "ip_conntrack_ftp", that is, comment out the configuration items in that line.
Add Rules
$ Vi/etc/sysconfig/iptables
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [5: 564]
: RH-Firewall-1-INPUT-[0: 0]
-A input-p tcp-m tcp -- dport 3306-j ACCEPT
-A input-j RH-Firewall-1-INPUT
-A forward-j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT-I lo-j ACCEPT
-A RH-Firewall-1-INPUT-p icmp-m icmp -- icmp-type any-j ACCEPT
-A RH-Firewall-1-INPUT-p esp-j ACCEPT
-A RH-Firewall-1-INPUT-p ah-j ACCEPT
-A RH-Firewall-1-INPUT-m state -- state RELATED, ESTABLISHED-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 53-j ACCEPT
-A RH-Firewall-1-INPUT-p udp-m state -- state NEW-m udp -- dport 53-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 22-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 25-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 80-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 8080-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 443-j ACCEPT
-A RH-Firewall-1-INPUT-j REJECT -- reject-with icmp-host-prohibited
COMMIT
It already contains Mysql database port 3306 and Tomcat port 8080. You can add or delete ports as needed.
-------------------------------------- Split line --------------------------------------
Disable the default firewall in CentOS 7.0 and enable the iptables firewall.
Iptables examples
Linux Firewall iptables
Basic use of iptables backup, recovery, and firewall scripts
Detailed description of firewall iptables usage rules in Linux
-------------------------------------- Split line --------------------------------------