按如下形式固定IPTables策略,可避免IPTables本身策略的备份与恢复操作(IPTables进行restore操作时会全量还原重置,而IPSet进行restore操作时是增量进行的):
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT DROP [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_tcp_acc_si src
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_tcp_acc_dp dst
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_tcp_acc_sidp src,dst
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_tcp_rej_si src
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_tcp_rej_dp dst
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_tcp_rej_sidp src,dst
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_udp_acc_si src
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_udp_acc_dp dst
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set in_udp_acc_sidp src,dst
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_udp_rej_si src
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_udp_rej_dp dst
-A INPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set in_udp_rej_sidp src,dst
-A INPUT -m state --state NEW -j REJECT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_tcp_acc_di src
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_tcp_acc_dp dst
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_tcp_acc_didp src,dst
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_tcp_rej_di src
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_tcp_rej_dp dst
-A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_tcp_rej_didp src,dst
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_udp_acc_di src
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_udp_acc_dp dst
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT -m set --set out_udp_acc_didp src,dst
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_udp_rej_di src
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_udp_rej_dp dst
-A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j REJECT -m set --set out_udp_rej_didp src,dst
-A OUTPUT -j LOG --log-prefix "iptables:"
-A OUTPUT -m state --state NEW -j REJECT
COMMIT