centos7 關閉firewall防火牆指令以及更換安裝iptables並配置
阿新 • • 發佈:2019-01-31
一、配置防火牆,開啟80埠、3306埠
CentOS
7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆。
1、關閉firewall:
systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機啟動2、安裝iptables防火牆 並編輯iptales
1)安裝iptables
#先檢查是否安裝了iptables service iptables status #安裝iptables yum install -y iptables #升級iptablesyum update iptables #安裝iptables-services yum install iptables-services
2)編輯防火牆配置檔案 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! #儲存退出 systemctl restart iptables.service #最後重啟防火牆使配置生效 systemctl enable iptables.service #設定防火牆開機啟動
vi /etc/selinux/config #SELINUX=enforcing #註釋掉 #SELINUXTYPE=targeted #註釋掉 SELINUX=disabled #增加 :wq! #儲存退出 setenforce 0 #使配置立即生效