centos7下部署iptables環境紀錄(關閉預設的firewalle)

散盡浮華發表於2016-08-23

 

CentOS7預設的防火牆不是iptables,而是firewall.
由於習慣了用iptables作為防火牆,所以在安裝好centos7系統後,會將預設的firewall關閉,並另安裝iptables進行防火牆規則設定

下面介紹centos7關閉firewall安裝iptables,並且開啟80埠、3306埠的操作記錄:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

1、關閉firewall:

[root@localhost ~]# systemctl stop firewalld.service            //停止firewall
[root@localhost ~]# systemctl disable firewalld.service        //禁止firewall開機啟動

2、安裝iptables防火牆

[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

二、關閉SELINUX

[root@localhost ~]# vim /etc/selinux/config
#SELINUX=enforcing           //註釋掉
#SELINUXTYPE=targeted           //註釋掉
SELINUX=disabled              //增加


[root@localhost ~]# setenforce 0       //使配置立即生效

相關文章