Centos iptables防火墙添加IP白名单,指定IP可访问端口
vi /etc/sysconfig/iptables
以下为我虚拟机的防火墙为例(Centos 7)
# sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -N whitelist -A whitelist -s xx.xx.xx.xx/32 -j ACCEPT ##添加IP到白名单 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j whitelist ##whitelist调用白名单IP列表,22端口只允许白名单IP使用 -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT ##无调用白名单,外网可访问 -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT ~
:wq 保存,重启防火墙生效
原文地址:https://www.cnblogs.com/erdi/p/9701049.html
时间: 2024-11-11 06:02:19