溫馨提示×

怎樣用CentOS iptables阻止特定IP

小樊
57
2025-07-22 15:11:27
欄目: 智能運維

要使用 CentOS 的 iptables 阻止特定 IP 地址,您可以按照以下步驟操作:

  1. 打開終端。

  2. 輸入以下命令以阻止特定 IP 地址(將 x.x.x.x 替換為您要阻止的 IP 地址):

sudo iptables -A INPUT -s x.x.x.x -j DROP

這將把來自指定 IP 地址的所有數據包丟棄,從而阻止該 IP 地址訪問您的服務器。

  1. 若要查看當前的 iptables 規則,請輸入以下命令:
sudo iptables -L
  1. 如果您想保存更改,以便在系統重啟后仍然生效,您需要安裝 iptables-services 軟件包(如果尚未安裝):
sudo yum install iptables-services
  1. 啟動并啟用 iptables 服務:
sudo systemctl start iptables
sudo systemctl enable iptables

現在,您已經成功阻止了特定 IP 地址訪問您的 CentOS 服務器。如果您以后想取消阻止該 IP 地址,只需刪除相應的 iptables 規則即可:

sudo iptables -D INPUT -s x.x.x.x -j DROP

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女