Firewall

如何在 Centos7 上使用防火牆刪除對埠的訪問?

  • November 7, 2021

如果使用 firewall-cmd 打開一個埠供公眾使用,我想將此埠限制為一個特定的 IP,我在這個SITE上找到了答案。

我使用以下內容打開它:

$ firewall-cmd --permanent --zone=public --add-port=10050/tcp
$ firewall-cmd --reload

現在使用我發現的資訊中的資訊,我想將此埠的訪問限制為特定的 IP 地址。我需要先從公共訪問中刪除此埠嗎?

或者我可以只添加如下的新規則,這將為我解決問題嗎?

$ firewall-cmd --new-zone=special
$ firewall-cmd --permanent --zone=special --add-rich-rule='
 rule family="ipv4"
 source address=”123.1.1.1"
 port protocol="tcp" port="10050" accept'

我嘗試了以下方法:

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --reload

但是當我執行以下命令時:

$ firewall-cmd --list-ports 

10050/tcp仍然顯示。

請理解我對伺服器端配置並不太熟悉。

Soultion :不要忘記–runtime-to-permanent

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --runtime-to-permanent
$ firewall-cmd --reload 

解決方案:不要忘記–runtime-to-permanent

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --runtime-to-permanent 
$ firewall-cmd --reload 
# firewall-cmd --zone=public --remove-port=12345/tcp --permanent
# firewall-cmd --reload

將 12345 替換為您要刪除的埠。

引用自:https://serverfault.com/questions/818996