10.19 iptables规则备份恢复

Linux防火墙—netfilter

1. 保存 iptables规则 

(默认规则保存到:/etc/sysconfig/iptables文件中。)

[[email protected] ~]# service iptables save

2. 备份 iptables规则重定向(保存)到指定路径 

[[email protected] ~]# iptables-save > /tmp/ipt.txt

查看保存的iptables规则 

[[email protected] ~]# cat /tmp/ipt.txt

3. 清空 iptables规则 

[[email protected] ~]# iptables -t nat -F

4. 恢复 iptables规则(刚刚备份的) 

[[email protected] ~]# iptables-restore < /tmp/ipt.txt

10.20 firewalld的9个zone

Linux防火墙-firewalled

1. 关闭 iptables(centos6 防火墙) 

[[email protected] ~]# systemctl disable iptables

[[email protected] ~]# systemctl stop iptables

2. 打开 firewalled(centos7防火墙 之前关掉了)

[[email protected] ~]# systemctl enable firewalld

[[email protected] ~]# systemctl start firewalld

3. firewalld 默认9zone(规则);默认zonepublic

4. 查看 firewalld 所有zone(共9个,默认zonepublic) :

[[email protected] ~]# firewall-cmd --get-zones

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

5. 查询 firewalled默认zone(规则)是什么(默认zonepublic)  

[[email protected] ~]# firewall-cmd --get-default-zone

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

6. 9个zone的详解:

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

10.21 firewalld关于zone的操作

1. 更改 firewalled默认zone(规则)

[[email protected] ~]# firewall-cmd --set-default-zone=work

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

2. 查看 指定网卡zone(规则)

firewall-cmd --get-zone-of-interface=网卡名

[[email protected] ~]# firewall-cmd --get-zone-of-interface=ens33

[[email protected] ~]# firewall-cmd --get-zone-of-interface=ens37

[[email protected] ~]# firewall-cmd --get-zone-of-interface=lo

3. 增加 指定网卡zone(规则)

firewall-cmd --zone=定义zone --add-interface=网卡名

[[email protected] ~]# firewall-cmd --zone=public --add-interface=ens37

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

[[email protected] ~]# firewall-cmd --zone=public --add-interface=lo

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

4. 更改 指定网卡zone

firewall-cmd --zone=新zone --change-interface=网卡名

[[email protected] ~]# firewall-cmd --zone=block --change-interface=ens33

[[email protected] ~]# firewall-cmd --zone=block --change-interface=ens37

[[email protected] ~]# firewall-cmd --zone=block --change-interface=lo

5. 删除 指定网卡zone(变成默认zone)

firewall-cmd --zone=网卡对应zone  --remove-interface=网卡名

[[email protected] ~]# firewall-cmd --zone=block  --remove-interface=ens33

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

6. 查看 系统所有网卡 对应zone(查看系统所有网卡所在的zone)

[[email protected] ~]# firewall-cmd --get-active-zones

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

10.22 firewalld关于service的操

services是zone下的一个子单元

(指定的一个端口:如http,到service下,就不会被限制过滤)  

http操作80端口   https操作443端口   ssh操作22端口  

1. 查看 系统所有的servie 

(zone下servie相当于白名单,添加http等到servie下,就不会过滤直接放行)

[[email protected] ~]# firewall-cmd --get-services10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

1.5 查看 默认zone 

[[email protected] ~]# firewall-cmd --get-default-zone

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

2. 查看 默认zone,包含哪些service 

[[email protected] ~]# firewall-cmd --list-services

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

3. 查看 指定zone,包含哪些service 

firewall-cmd --zone=指定zone --list-services

[[email protected] ~]# firewall-cmd --zone=work --list-services

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

4. 增加 http指定zone下(临时储存在内存中) 

[[email protected] ~]# firewall-cmd --zone=work --add-service=http10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

5. 增加 http指定zone下(永久保存在zone配置文件) 

[[email protected] ~]# firewall-cmd --zone=work --add-service=http --permanent

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

6. 查看 zone配置文件所在目录 

(更新永久保存到配置文件,会重新生成.xml文件,之前的配置文件变成.xml.old)

[[email protected] ~]# ls /etc/firewalld/zones

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

7. 查看 zone配置文件内容 

[[email protected] ~]# cat /etc/firewalld/zones/work.xml

8. 查看 firewalld配置文件所在目录 (默认无,还没有更改过firewalld配置文件)

[[email protected] ~]# ls /etc/firewalld/services

9. 查看 zone配置文件模板 

[[email protected] ~]# ls /usr/lib/firewalld/zones

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

10. 查看 services配置文件模板 

[[email protected] ~]# ls /usr/lib/firewalld/services

•需求:ftp服务自定义端口1121

•需要在work zone下面放行ftp

1. 拷贝 services/ftp.xml配置文件/etc/... 

[[email protected] ~]# cp /usr/lib/firewalld/services/ftp.xml  /etc/firewalld/services

2. 编辑 ftp配置文件,22端口更改为自定义的 1121

[[email protected] ~]# vi /etc/firewalld/services/ftp.xml

更改: port="1121"

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

3. 拷贝 zones/work.xml配置文件/etc/... 

(注意:上面做实验把默认zone设定为work了,http设定到work的配置文件了,永久保存就会产生了一个work.xml文件,这里复制的模板覆盖掉之前的文件就可以了!)

[[email protected] ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones

4. 编辑 work配置文件,添加一条 service名字ftp 

[[email protected] ~]# vi /etc/firewalld/zones/work.xml

添加一行: <service name="ftp"/>

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

5. 重新加载 :

[[email protected] ~]# firewall-cmd --reload

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21

6. 查看zone(work)下,包含service(ftp):

[[email protected] ~]# firewall-cmd --zone=work --list-services

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.2110.19 iptables规则备份和恢复 10.20 firewalld的9个zone10.21










本文转自 主内安详 51CTO博客,原文链接:http://blog.51cto.com/zhuneianxiang/2065554,如需转载请自行联系原作者

相关文章: