Linux CentOS 7 防火牆與端口設置操作


CentOS升級到7之后用firewall代替了iptables來設置Linux端口,

下面是具體的設置方法:

[]:選填

<>:必填

[<zone>]:作用域(block、dmz、drop、external、home、internal、public、trusted、work)

<port>:端口號

[-<port>]:或者端口范圍

<protocol>:端口協議(tcp、udp)協議目前支持這四種類型

[<seconds>]:過期時間,使用N秒后自動關閉(秒)

[--permanent]:永久設置,在重啟后依然保證設置可用,如果不加此項,重啟后端口會恢復關閉狀態

注:設置端口后要重啟防火牆使其生效 firewall-cmd --complete-reload

 

1、檢查端口狀態

yes:已開通 

no:未開通 

firewall-cmd --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

查看已開放的端口

firewall-cmd --zone=public --list-ports

 

2、啟用端口

success:執行成功

warning:警告xxx

firewall-cmd --add-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
firewall-cmd [--permanent] [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

3、禁用端口 

success:執行成功

warning:警告xxx

firewall-cmd --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

 

4、防火牆重啟

--reload:不改變狀態的條件下重啟防火牆

--complete-reload:狀態信息將會丟失,當防火牆有問題時可以使用,如,狀態信息和防火牆規則都正常卻無法建立任何鏈接的情況等

firewall-cmd --reload
firewall-cmd --complete-reload
例子

 

6、查看防火牆狀態

命令1:firewall-cmd --state

命令2:systemctl status firewalld

 

7、查看、打開、關閉應急模式

(應急模式阻斷所有網絡連接,防止出現緊急狀況)

firewall-cmd --query-panic

 

firewall-cmd --panic-on

 firewall-cmd --panic-off

8、打開、關閉、重啟防火牆 

systemctl stop firewalld
systemctl start firewalld
systemctl restart firewalld

 

 9、開啟/關閉 開機自啟動防火牆

systemctl enable firewalld
systemctl disable firewalld

查詢防火牆服務是否開機啟動:
systemctl is-enabled firewalld

 

10、其他操作

查看版本: firewall-cmd --version
查看幫助: firewall-cmd --help
查看區域信息:  firewall-cmd --get-active-zones
查看指定接口所屬區域: firewall-cmd --get-zone-of-interface=網卡名稱

 

查詢已經啟動的服務列表:systemctl list-unit-files|grep enabled
 

 查詢啟動失敗的服務列表:systemctl --failed

 

 
 

 

 

 
        

 

 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM