Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

CentOS 7 如何開放埠號:firewalld 常用操作整理

CentOS 7 用 firewalld 取代了原本的 iptables,對應的命令列工具是 firewall-cmd。以下是最常翻到的幾個操作。

查看版本

[root@192 ~]# firewall-cmd --version
輸出例如 0.3.9,這是本機的版本號。

查詢某個埠是否已開放

[root@192 ~]# firewall-cmd --query-port=8080/tcp
回 no 代表未開放,回 yes 代表已開放。

開放指定埠

[root@192 ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
回 success 即設定成功。這裡的 --permanent 表示永久生效;如果漏掉這個參數,重開機後埠又會回到未開放狀態。

因為 permanent 寫的是常駐設定,改完要 firewall-cmd --reload 才會套用到執行中的規則;若不加 permanent 直接改,則是立即生效但開機失效,這兩者的差別是初學時最容易踩的坑。

其他常用操作

移除規則:--remove-port=8080/tcp;列出目前 zone 的所有設定:--list-all;查詢服務是否運行:systemctl status firewalld。除了單一埠,也可以/protocol 或整個 service 為單位放行,例如 --add-service=http。

Copyright © Linux教程網 All Rights Reserved