iptables规则保存,默认保存的位置路径:/etc/sysconfig/iptables文件里;网络
service iptables save
iptables规则备份到指定路径ssh
iptables-save > /tmp/ipt.txt
iptables恢复规则能够选项将/etc/sysconfig/iptables文件作备份,也可使用下面命令将输出的文件恢复:tcp
iptables-restore < /tmp/ipt.txt
鉴于上节课作实验咱们关闭了firewalld打开了iptables,咱们须要关闭iptables和开启firewalldrest
1.关闭iptablescode
systemctl disable iptables #禁用开机启动 systemctl stop iptables #中止iptables
2.启用firewalldxml
systemctl enable firewalld #设置开机启动 systemctl start firewalld #启动firewalld
3.从新查看规则发现默认规则已经和以前不一样,说明已经更改过来ip
iptables -nvL
firewalld默认有9个zone,zone是firewalld的最小单位,默认zone为public;utf-8
查看firewalld的9个zone的命令路由
[root@yolks1 ~]# firewall-cmd --get-zones block dmz drop external home internal public trusted work
查看firewalld默认使用的zonerem
[root@yolks1 ~]# firewall-cmd --get-default-zone public
上面9个zone的简介:
设定默认的zone为work
[root@yolks1 ~]# firewall-cmd --set-default-zone=work success [root@yolks1 ~]# firewall-cmd --get-default-zone work
查看指定网卡所在的zone
[root@yolks1 ~]# firewall-cmd --get-zone-of-interface=ens33 work
给指定网卡设置zone
[root@yolks1 ~]# firewall-cmd --zone=home --add-interface=ens33 The interface is under control of NetworkManager, setting zone to 'home'. success [root@yolks1 ~]# firewall-cmd --get-zone-of-interface=ens33 home
针对网卡更改zone
[root@yolks1 ~]# firewall-cmd --zone=work --change-interface=ens33 The interface is under control of NetworkManager, setting zone to 'work'. success [root@yolks1 ~]# firewall-cmd --get-zone-of-interface=ens33 work
针对网卡删除zone
firewall-cmd --zone=work --remove-interface=ens33
查看系统全部网卡所在的zone
[root@yolks1 ~]# firewall-cmd --get-active-zones work interfaces: ens33
在/usr/lib/firewalld/services/目录中,还保存了另一类配置文件,每一个文件对应一项具体的网络服务,如ssh服务等。
与之对应的配置文件中记录了各项服务所使用的tcp/udp端口,在最新版的firewalld中默认已经定义了70多种服务供咱们使用。
zone就是调用了不一样的service而实现了不一样的效果。
列出当前系统全部的service
firewall-cmd --get-service
查看当前zone下有哪些service
firewall-cmd --list-services
查看指定zone下有哪些service
firewall-cmd --zone=public --list-services
把http和ftp增长到public zone下面(临时保存)
[root@yolks1 ~]# firewall-cmd --zone=public --add-service=http --add-service=ftp success
以修改配置文件来增长service
[root@yolks1 ~]# firewall-cmd --zone=public --add-service=http --permanent success
查看zone对应的配置文件(配置文件在/etc/firewalld/zones/下,每次修改完配置文件,他都会把旧的配置文件后缀名加上.old也保存在目录下)
[root@yolks1 ~]# ls /etc/firewalld/zones/ public.xml public.xml.old [root@yolks1 ~]# cat /etc/firewalld/zones/public.xml #查看配置文件 <?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <service name="ssh"/> <service name="dhcpv6-client"/> <service name="http"/> </zone>
在**/usr/lib/firewalld/services下保存的是services的模板
在/usr/lib/firewalld/zone下保存的是zone**的模板
需求:把ftp服务自定义端口1121,须要在work zone下面放行ftp
1.复制模板到service下
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
2.修改ftp的配置文件,修改端口1121
3.复制模板到zones下
cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
4.修改work.xml的配置文件,把ftp加到里面
5.从新查看workzone的服务
[root@yolks1 ~]# firewall-cmd --zone=work --list-service ssh dhcpv6-client ftp