Centos防火墙添加IP白名单


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   保存,重启防火墙生效


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM