在CentOS上安裝iptables的步驟如下:
更新系統:
sudo yum update -y
安裝iptables:
sudo yum install iptables -y
啟動iptables服務:
sudo systemctl start iptables
設置iptables開機自啟:
sudo systemctl enable iptables
檢查iptables狀態:
sudo systemctl status iptables
CentOS 7及以上版本默認使用firewalld作為防火墻管理工具,它提供了更友好的圖形界面和更靈活的配置選項。
安裝firewalld:
sudo yum install firewalld -y
啟動firewalld服務:
sudo systemctl start firewalld
設置firewalld開機自啟:
sudo systemctl enable firewalld
檢查firewalld狀態:
sudo systemctl status firewalld
配置firewalld規則:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-zones
sudo firewall-cmd --set-default-zone=public
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
iptables-restore
命令來保存和恢復規則。sudo iptables-save > /etc/sysconfig/iptables
sudo iptables-restore < /etc/sysconfig/iptables
通過以上步驟,你應該能夠在CentOS上成功安裝并配置iptables或firewalld。