轉載 CentOS 7 為firewalld添加開放端口及相關資料
1、運行、停止、禁用firewalld
啟動:# systemctl start firewalld
查看狀態:# systemctl status firewalld 或者 firewall-cmd --state
停止:# systemctl disable firewalld
禁用:# systemctl stop firewalld
查看firewall是否運行,下面兩個命令都可以
systemctl status firewalld.service firewall-cmd --state
查看default zone和active zone
我們還沒有做任何配置,default zone和active zone都應該是public
firewall-cmd --get-default-zone firewall-cmd --get-active-zones
查看當前開了哪些端口
其實一個服務對應一個端口,每個服務對應/usr/lib/firewalld/services下面一個xml文件。
firewall-cmd --list-services
查看還有哪些服務可以打開
firewall-cmd --get-services
查看所有打開的端口:
firewall-cmd --zone=public --list-ports
更新防火牆規則:
firewall-cmd --reload
添加一個服務到firewalld
firewall-cmd --add-service=http //http換成想要開放的service
這樣添加的service當前立刻生效,但系統下次啟動就失效,可以測試使用。要永久開發一個service,加上 --permanent
firewall-cmd --permanent --add-service=http
如果要添加的端口並沒有服務對應
就要新建一個服務,在/usr/lib/firewalld/services,隨便拷貝一個xml文件到一個新名字,比如myservice.xml,把里面的
<?xml version="1.0" encoding="utf-8"?> <service> <short>Transmission-client</short> <description>Transmission is a lightweight GTK+ BitTorrent client.</description> <port protocol="tcp" port="51413"/> </service>
short改為想要名字(這個名字只是為了人來閱讀,沒有實際影響。重要的是修改 protocol和port。修改完保存。我的經驗是這是要重啟firewalld服務,systemctl restart firewalld.service
,否則可能提示找不到剛才新建的service。然后把新建的service添加到
firewalld
firewall-cmd --permanent --add-service=myservice
重啟firewalld 生效
5分鍾理解Centos7防火牆firewalld http://www.cnblogs.com/stevenzeng/p/5152324.html
-------------------------------------------------------------------------------------------------------------
啟動一個服務:systemctl start firewalld.service
關閉一個服務:systemctl stop firewalld.service
重啟一個服務:systemctl restart firewalld.service
顯示一個服務的狀態:systemctl status firewalld.service
在開機時啟用一個服務:systemctl enable firewalld.service
在開機時禁用一個服務:systemctl disable firewalld.service
查看服務是否開機啟動:systemctl is-enabled firewalld.service
查看已啟動的服務列表:systemctl list-unit-files|grep enabled
查看啟動失敗的服務列表:systemctl --failed
3.配置firewalld-cmd