iptables -F #清空全部規則鏈服務器
iptables -X #刪除特定手工設置的鏈tcp
iptables -P INPUT DROP #默認INPUT規則 丟棄spa
iptables -P OUTPUT DROP #默認OUTPUT規則 丟棄ip
iptables -P FORWARD DROP #默認FORWARD規則 丟棄同步
iptables -A INPUT -p tcp --dport 22 -i eth0 -j ACCEPT #開SSH服務進站端口it
iptables -A INPUT -p tcp --dport 80 -i eth0 -j ACCEPT #開WEB服務進站端口table
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT #對SSH的服務進入的數據包開啓出站端口iptables
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT #對WEB的服務進入的數據包開啓出站端口udp
iptables -A INPUT -i lo -p all -j ACCEPT #容許本地環回數據request
iptables -A INPUT -p udp -m udp --sport 53 -j ACCEPT #來自遠程DNS服務器53端口的數據包進站經過
iptables -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT #進入本地服務器53端口的數據包進站經過
iptables -A INPUT -p icmp -j ACCEPT #ICPM數據包可進入本地服務器
iptables -A OUTPUT -p icmp -j ACCEPT #對對方ICMP數據包迴應(ping命令迴應數據包)
iptables -A INPUT -p tcp --sport 3306 -i eth0 -j ACCEPT #來自遠程MYSQL服務器3306端口的數據包進站經過
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #容許全部已經創建的和相關的鏈接
# 防止nmap探測
iptables -A INPUT -p tcp --dport 1:1024 -j DROP
iptables -A INPUT -p udp --dport 1:1024 -j DROP
# 防止同步包洪水(Sync Flood)
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# 防止各類端口掃描
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# Ping洪水攻擊(Ping of Death)
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Null Scan(possibly)XiKc.om
iptables -A INPUT -i eth0 -p tcp --tcp-flags ALL NONE -j DROP