查看iptables规则
iptables -L
保存规则(如原始无该文件,保存后即有文件):(需要设置:INPUT DROP [0:0])
iptables-save > /etc/iptables.rules
5、执行以下命令,使规则生效
iptables-restore < /etc/iptables.rules
6 设置白名单:
-N whitelist
#设置白名单ip段
-A INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8280 -j whitelist
-A whitelist -s ip1 -j ACCEPT
-A whitelist -s ip2 -j ACCEPT
保存以及生效
iptables-save > /etc/iptables.rules
iptables-restore < /etc/iptables.rules
具体例子:
# Generated by iptables-save v1.4.12 on Tue Jun 25 19:46:50 2019
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [695:460921]
:syn-flood - [0:0]
:whitelist - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j whitelist
-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT
-A INPUT -p icmp -m limit --limit 1/sec --limit-burst 10 -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
-A syn-flood -j REJECT --reject-with icmp-port-unreachable
-A whitelist -s ip1 -j ACCEPT
-A whitelist -s ip2 -j ACCEPT
COMMIT
# Completed on Tue Jun 25 19:46:50 2019
133

被折叠的 条评论
为什么被折叠?



