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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐