在 CentOS 系统中,你可以使用 iptables
命令来修改防火墙规则
- 查看当前的 iptables 规则:
sudo iptables -L -n -v
- 添加新的 iptables 规则:
例如,添加一条规则以允许来自特定 IP 地址(例如 192.168.1.10)的 SSH 访问:
sudo iptables -A INPUT -p tcp -s 192.168.1.10 --dport 22 -j ACCEPT
- 删除特定的 iptables 规则:
例如,删除上面添加的允许特定 IP 地址访问 SSH 的规则:
sudo iptables -D INPUT -p tcp -s 192.168.1.10 --dport 22 -j ACCEPT
- 保存当前的 iptables 规则:
sudo service iptables save
- 重启 iptables 服务以应用更改:
sudo service iptables restart
注意:在使用 iptables
时,请确保你有足够的权限。根据需要,你可能需要使用 sudo
命令。另外,根据你的CentOS版本,服务名称可能是iptables
或firewalld
,请根据实际情况进行调整。