Centos 7 防火牆配置

基本配置

操作系統環境:CentOS Linux release 7.0.1406(Core) 64位
CentOS 7.0默認使用的是firewall作爲防火牆,這裏改爲iptables防火牆步驟。

1、關閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)

2、iptables防火牆(這裏iptables已經安裝,下面進行配置)
vi/etc/sysconfig/iptables #編輯防火牆配置文件
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus 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 -jACCEPT
-A INPUT -i lo -jACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
-A INPUT -j REJECT--reject-with icmp-host-prohibited
-A FORWARD -jREJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出

備註:這裏使用80和8080端口爲例。***部分一般添加到“-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT”行的上面或者下面,切記不要添加到最後一行,否則防火牆重啓後不生效。
systemctlrestart iptables.service #最後重啓防火牆使配置生效
systemctlenable iptables.service #設置防火牆開機啓動

全文完..........

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

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

iptables—包過濾(網絡層)防火牆 [這裏寫鏈接內容](http://www.linuxidc.com/Linux/2013-08/88423.htm)

Linux防火牆iptables詳細教程 [這裏寫鏈接內容](http://www.linuxidc.com/Linux/2013-07/87045.htm)

iptables+L7+Squid實現完善的軟件防火牆 [這裏寫鏈接內容](http://www.linuxidc.com/Linux/2013-05/84802.htm)

iptables的備份、恢復及防火牆腳本的基本使用 [這裏寫鏈接內容](http://www.linuxidc.com/Linux/2013-08/88535.htm)

Linux下防火牆iptables用法規則詳解 [這裏寫鏈接內容](http://www.linuxidc.com/Linux/2012-08/67952.htm)

開發端口:

//樣例
CentOS升級到7之後,發現無法使用iptables控制Linuxs的端口,google之後發現Centos 7使用firewalld代替了原來的iptables。下面記錄如何使用firewalld開放Linux端口:

開啓端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

命令含義:

--zone #作用域

--add-port=80/tcp  #添加端口,格式爲:端口/通訊協議

--permanent  #永久生效,沒有此參數重啓後失效

重啓防火牆

firewall-cmd --reload
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章