首頁 > 軟體

CentOS 7下iptables相關

2020-06-16 17:54:58

CentOS 7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆。

1、關閉firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機啟動

2、安裝iptables防火牆

yum install iptables-services #安裝

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 #設定防火牆開機啟動

--------------------------------------分割線 --------------------------------------

CentOS 7.0關閉預設防火牆啟用iptables防火牆  http://www.linuxidc.com/Linux/2015-05/117473.htm

iptables使用範例詳解 http://www.linuxidc.com/Linux/2014-03/99159.htm

Linux防火牆iptables詳細教學 http://www.linuxidc.com/Linux/2013-07/87045.htm

iptables的備份、恢復及防火牆指令碼的基本使用 http://www.linuxidc.com/Linux/2013-08/88535.htm

Linux下防火牆iptables用法規則詳解 http://www.linuxidc.com/Linux/2012-08/67952.htm

--------------------------------------分割線 --------------------------------------

本文永久更新連結地址http://www.linuxidc.com/Linux/2015-08/121915.htm


IT145.com E-mail:sddin#qq.com