我的伺服器iptables配置
阿新 • • 發佈:2018-11-23
我的伺服器iptables配置。記錄用。
# Generated by iptables-save v1.4.21 on Fri Apr 21 12:24:07 2017
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [18:1210]
:POSTROUTING ACCEPT [0:0]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -s 172.17.0.2/32 -d 172.17.0.2/32 -p tcp -m tcp --dport 1194 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
-A DOCKER ! -i docker0 -p tcp -m tcp --dport 1194 -j DNAT --to-destination 172.17.0.2:1194
COMMIT
# Completed on Fri Apr 21 12:24:07 2017
# Generated by iptables-save v1.4.21 on Fri Apr 21 12:24:07 2017
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [18:1210]
:DOCKER - [0:0]
:DOCKER-ISOLATION - [0:0]
# 允許外部輸入(TCP協議28埠)
-A INPUT -i eth0 -p tcp --dport 28 -m state --state NEW,ESTABLISHED -j ACCEPT
# 允許外部輸入(TCP協議80埠)
-A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# 禁止外部輸入(TCP協議1194埠)
-A INPUT -i eth0 -p tcp --dport 1194 -m state --state NEW,ESTABLISHED -j DROP
# 禁止外部輸入(TCP協議3306埠)
-A INPUT -i eth0 -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j DROP
# 允許外部輸入(TCP連線80埠)
-A INPUT -i eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
# 允許外部輸入(TCP連線443埠)
-A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
# 允許外部輸入(UDP協議的53埠)
-A INPUT -i eth0 -p udp --sport 53 -m udp -j ACCEPT
# 允許外部輸入(PING應答包)
-A INPUT -i eth0 -p icmp --icmp-type echo-reply -j ACCEPT
# 允許外部輸入(PING請求包)
-A INPUT -i eth0 -p icmp --icmp-type echo-request -j ACCEPT
# 允許內環輸入
-A INPUT -i lo -j ACCEPT
# 允許docker輸入
-A INPUT -i docker0 -j ACCEPT
-A FORWARD -j DOCKER-ISOLATION
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
# 允許輸出(TCP協議的28埠)
-A OUTPUT -o eth0 -p tcp --sport 28 -m state --state ESTABLISHED -j ACCEPT
# 允許輸出(TCP協議的80埠)
-A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
# 禁止輸出(TCP協議的1194埠)
-A OUTPUT -o eth0 -p tcp --sport 1194 -m state --state ESTABLISHED -j DROP
# 禁止輸出(TCP協議的3306埠)
-A OUTPUT -o eth0 -p tcp --sport 3306 -m state --state ESTABLISHED -j DROP
# 允許輸出(TCP協議的80埠)
-A OUTPUT -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# 允許輸出(TCP協議的443埠)
-A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
# 允許輸出(UDP協議的53埠)
-A OUTPUT -o eth0 -p udp --dport 53 -m udp -j ACCEPT
# 允許輸出(PING請求包)
-A OUTPUT -o eth0 -p icmp --icmp-type echo-request -j ACCEPT
# 允許輸出(PING應答包)
-A OUTPUT -o eth0 -p icmp --icmp-type echo-reply -j ACCEPT
# 允許內環輸出
-A OUTPUT -o lo -j ACCEPT
# 允許docker輸出
-A OUTPUT -o docker0 -j ACCEPT
-A DOCKER -d 172.17.0.2/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 1194 -j ACCEPT
-A DOCKER-ISOLATION -j RETURN
COMMIT
# Completed on Fri Apr 21 12:24:07 2017