2021-05-12 14:32:11
CentOS 7中使用iptables
2020-06-16 17:09:38
CentOS 7中使用iptables
1、關閉firewall
systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機啟動
2、安裝iptables防火牆
#安裝 yum install iptables-services
3、編輯防火牆組態檔
vim /etc/sysconfig/iptables
顯示:
# sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 20 -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 #設定防火牆開機啟動
4、關閉SELINUX
vim /etc/selinux/config
#SELINUX=enforcing #注釋掉 #SELINUXTYPE=targeted #注釋掉 SELINUX=disabled #增加
:wq! #儲存退出
setenforce 0 #使設定立即生效
更多iptables相關教學見以下內容:
CentOS 7.0關閉預設防火牆啟用iptables防火牆 http://www.linuxidc.com/Linux/2015-05/117473.htm
Iptables工作原理使用詳解 http://www.linuxidc.com/Linux/2016-09/134945.htm
Ubuntu 14.04 設定iptables防火牆 http://www.linuxidc.com/Linux/2017-02/140556.htm
Linux下編譯安裝iptables http://www.linuxidc.com/Linux/2017-04/142615.htm
iptables的備份、恢復及防火牆指令碼的基本使用 http://www.linuxidc.com/Linux/2013-08/88535.htm
Iptables工作原理使用詳解 http://www.linuxidc.com/Linux/2016-09/134945.htm
CentOS7下iptables設定過程 http://www.linuxidc.com/Linux/2017-01/139622.htm
Linux下iptables防火牆設定 http://www.linuxidc.com/Linux/2015-10/123843.htm
Linux防火牆iptables詳解 http://www.linuxidc.com/Linux/2016-12/138474.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2017-08/146083.htm
相關文章