在 CentOS 中,防火墙通常是 firewalld(CentOS 7 及以后)。下面按常见场景说明如何放行指定 IP。
systemctl status firewalld
如果未运行,可启动:
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="22" accept'
firewall-cmd --reload
firewall-cmd --list-all
或查看富规则:
firewall-cmd --list-rich-rules
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.100" accept'
firewall-cmd --reload
iptables -A INPUT -s 192.168.1.100 -j ACCEPT
service iptables save
service iptables restart
如果你能说明:
我可以给你更精确的一条命令。