在CentOS系統中,你可以使用firewalld或iptables來阻止惡意IP訪問。以下是兩種方法的詳細步驟:
安裝firewalld(如果尚未安裝):
sudo yum install firewalld
啟動firewalld服務:
sudo systemctl start firewalld
啟用firewalld服務(使其在系統啟動時自動運行):
sudo systemctl enable firewalld
添加規則阻止惡意IP:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="惡意IP地址" reject'
例如,要阻止IP地址為192.168.1.100
的訪問:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject'
重新加載firewalld配置:
sudo firewall-cmd --reload
安裝iptables(如果尚未安裝):
sudo yum install iptables-services
啟動iptables服務:
sudo systemctl start iptables
啟用iptables服務(使其在系統啟動時自動運行):
sudo systemctl enable iptables
添加規則阻止惡意IP:
sudo iptables -A INPUT -s 惡意IP地址 -j DROP
例如,要阻止IP地址為192.168.1.100
的訪問:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
保存iptables規則:
sudo service iptables save
通過以上步驟,你可以有效地阻止惡意IP訪問你的CentOS系統。