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