CentOS7中用firewalld替代了iptables,默認情況下iptables是沒有安裝的,如果習慣使用iptables可以將firewalld關掉換成iptables。
1.首先關閉firewalld服務
systemctl stop firewalld
systemctl mask firewalld
systemctl disable firewalld
2.安裝iptables
yum -y install iptables
3.配置iptables規則
# Generated by iptables-save v1.4.21 on Thu Sep 10 02:27:20 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -p udp -m udp --dport 161 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -j ACCEPT
COMMIT
# Completed on Thu Sep 10 02:27:20 2015
3.開啟iptables服務
systemctl enable iptables
systemctl start iptables
4.保存
service iptables save
service iptables restart
5.開機啟動
chkconfig iptables on
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。