iptables 规则备份和恢复

备份

# service iptables save 

/etc/sysconfig/iptables // 默认保存的位置

指定备份位置

[root@localhost ~]# iptables-save > /tmp/ipt.txt
[root@localhost ~]# cat /tmp/ipt.txt
# Generated by iptables-save v1.4.21 on Fri Dec  1 21:16:41 2017
*filter
:INPUT DROP [9:702]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [262:26184]
-A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.8.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
COMMIT
# Completed on Fri Dec  1 21:16:41 2017

恢复备份的规则

[root@localhost ~]# iptables-restore < /tmp/ipt.txt