centos7下部署iptables環境紀錄(關閉默認的firewalle)
阿新 • • 發佈:2017-12-30
配置 highlight pad localhost custom -a 記錄 ont fire
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:
1 2 |
[root@localhost ~] # systemctl stop firewalld.service //停止firewall [root@localhost ~] # systemctl disable firewalld.service //禁止firewall開機啟動
|
2、安裝iptables防火墻
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[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
1 2 3 4 5 6 7 |
[root@localhost ~] # vim /etc/selinux/config
#SELINUX=enforcing //註釋掉
#SELINUXTYPE=targeted //註釋掉
SELINUX=disabled // 增加
[root@localhost ~] # setenforce 0 //使配置立即生效
|
centos7下部署iptables環境紀錄(關閉默認的firewalle)