查看firewall是否運行,下面兩個命令都可以
systemctl status firewalld.service
firewall-cmd --state
查看default zone和active zone
我們還沒有做任何配置,default zone和active zone都應(yīng)該是public
firewall-cmd --get-default-zone
firewall-cmd --get-active-zones
查看當(dāng)前開了哪些服務(wù)
其實一個服務(wù)對應(yīng)一個端口奇适,每個服務(wù)對應(yīng)/usr/lib/firewalld/services下面一個xml文件右莱。
firewall-cmd --list-services
查看開放了哪些端口
sudo firewall-cmd --zone=public --list-ports
查看還有哪些服務(wù)可以打開
firewall-cmd --get-services
添加一個服務(wù)到firewalld
firewall-cmd --add-service=http //http換成想要開放的service
這樣添加的service當(dāng)前立刻生效炬转,但系統(tǒng)下次啟動就失效验游,可以測試使用浓瞪。要永久開發(fā)一個service宏邮,加上 --permanent
firewall-cmd --permanent --add-service=http
Note1: Type –remove-service=http to deny the http service.
Note2: The firewall-cmd –reload command is necessary to activate the change. Contrary to the –complete-reload option, current connections are not stopped.
Note3: If you only want to temporarily add a service, don’t use the –permanent option and don’t reload the firewall configuration. If you reload the firewall configuration, you cancel all the operation.
如果要添加的端口并沒有服務(wù)對應(yīng)
就要新建一個服務(wù)根盒,在/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舵匾。修改完保存。我的經(jīng)驗是這是要重啟firewalld服務(wù)谁不,systemctl restart firewalld.service
坐梯,否則可能提示找不到剛才新建的service。然后把新建的service添加到firewalld
firewall-cmd --permanent --add-service=myservice
重啟firewalld 生效
firewall-cmd --reload
直接開放端口
[root@centos7 ~]# firewall-cmd --permanent --add-port=100/tcp
success
[root@centos7 ~]# firewall-cmd --reload
success