iptables规则备份和恢复 ,firewalld的9个zone , firewalld关于zone的操作, firewalld关于service的操作

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
  • 需求:
  1. 若不想保存到这个配置文件中,把规则保存保存到另一个文件中
  2. 使用命令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恢复刚备份的规则

  1. 先将之前备份的规则清空下iptables -t nat -F
  2. 再用iptables -t nat -nvL查看到规则都被清空了
  3. 再恢复之前备份的规则,命令iptables-restore < /tmp/ipt.txt
  4. 在使用命令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就好比一个规则集
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值