iptables规则的备份和恢复
- 保存和备份iptables规则
- service iptables save //会把规则保存到/etc/sysconfig/iptables
- 把iptables规则备份到my.ipt文件中
- iptables-save > my.ipt
- 恢复刚才备份的规则
- iptables-restore < my.ipt
将iptables规则保存到其他文件中
- service iptables save 这个命令会把规则保存到配置文件中/etc/sysconfig/iptables
- 需求:
- 若不想保存到这个配置文件中,把规则保存保存到另一个文件中
- 使用命令iptables-save将文件重定向到 /tmp/ipt.txt 文件中——>文件名称随便起
[root@hf ~]# iptables-save > /tmp/ipt.txt
[root@hf ~]# cat /tmp/ipt.txt //会看到保存的规则——>这里的和视频的不同,感觉nat表应用哪里挂掉了
# Generated by iptables-save v1.4.21 on Fri Dec 1 23:01:03 2017
*nat
-A PREROUTING -j PREROUTING_direct
-A PREROUTING -j PREROUTING_ZONES_SOURCE
COMMIT
# Completed on Fri Dec 1 23:01:03 2017
将iptables恢复刚备份的规则
- 先将之前备份的规则清空下iptables -t nat -F
- 再用iptables -t nat -nvL查看到规则都被清空了
- 再恢复之前备份的规则,命令iptables-restore < /tmp/ipt.txt
- 在使用命令iptables -t nat -nvL 会查看到清空的规则又回来了
- 备份的规则,只有恢复的时候会用到,若是服务器一重启,就想要加载一些规则,那最好将规则放
- 到/etc/sysconfig/iptables文件中去
firewalld的9个zone
Linux防火墙-firewalld
- 打开firewalld
- systemctl disable iptables
- systemctl stop iptables
- systemctl enable firewalld
- systemctl start firewalld
- firewalld默认有9个zone
- 默认zone为public
- firewall-cmd --get-zones //查看所有zone
- firewall-cmd --get-default-zone//查看默认zone
firewalld防火墙机制
- 因为之前禁掉了firewalld,打开了iptables,所以现在需要 打开firewalld,禁掉iptables
打开firewalld
[root@hf ~]# systemctl disable iptables
[root@hf ~]# systemctl stop iptables
[root@hf ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@hf ~]# systemctl start firewalld
[root@hf ~]#
这时用iptables -nvL和iptables -t nat -nvL查看规则,会看到增加了很多的链
- firewalld默认有9个zone,zone是firewalld的一个单位,默认使用public zone——>每个zone就好比一个规则集