CentOS7默認的防火牆不是iptables,而是firewall.
因爲習慣了用iptables做爲防火牆,因此在安裝好centos7系統後,會將默認的firewall關閉,並另安裝iptables進行防火牆規則設定linux
下面介紹centos7關閉firewall安裝iptables,而且開啓80端口、3306端口的操做記錄:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)vim
一、關閉firewall:centos
[root@localhost ~]# systemctl stop firewalld.service //中止firewall [root@localhost ~]# systemctl disable firewalld.service //禁止firewall開機啓動
二、安裝iptables防火牆bash
[root@localhost ~]# yum install iptables-services //安裝 [root@localhost ~]# vim /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 [root@localhost ~]# systemctl restart iptables.service //最後重啓防火牆使配置生效 [root@localhost ~]# systemctl enable iptables.service //設置防火牆開機啓動 [root@localhost ~]# iptables -L //查看防火牆規則,默認的是-t filter,若是是nat表查看,即iptables -t nat -L
2、關閉SELINUXtcp
[root@localhost ~]# vim /etc/selinux/config #SELINUX=enforcing //註釋掉 #SELINUXTYPE=targeted //註釋掉 SELINUX=disabled //增長 [root@localhost ~]# setenforce 0 //使配置當即生效