centos7.3預設使用的防火牆應該是firewall,而不是iptables。而我們xxmj伺服器使用的是iptables防火牆。所以,在配置防火牆之前,我們需要先關閉firewall,安裝iptables。
1.關閉firewall
service firewalld stop
systemctl disable firewalld.service #禁止firewall開機啟動
2.安裝iptables防火牆
yum install iptables-services
3.編輯iptables防火牆配置
vi /etc/sysconfig/iptables #編輯防火牆配置檔案
下邊是一個完整的配置檔案:
Firewall configuration written by system-config-firewall
Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #儲存退出
4.開啟iptables
service iptables start #開啟
systemctl enable iptables.service #設定防火牆開機啟動