iptables规则备份和恢复/firewalld的zone及操做

iptables规则的备份和恢复

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的9个zone

鉴于上节课作实验咱们关闭了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的简介:

  • drop(丢弃):任何接收的网络数据包都被抛弃,没有任何回复。仅能有发送出去的网络链接。
  • block(限制):任何接收的网络链接都被IPv4的icmp-host-prohibited信息和IPv6的icmp-adm-prohibited信息所拒绝。
  • public(公共):在公共区域使用,不能相信网络内的其余计算机不会对你的计算机形成危害,只能接收通过选取的链接
  • external(外部):特别是为路由器启用了假装功能的外部网。你不能信任来自网络的其余计算,不能相信它们不会对你的计算机形成危害,只能接收通过选择的链接。
  • dmz(非军事区):用于你的非军事区内的计算机,此区域内可公开访问,能够有限地进入你的内部网络,仅仅接收通过选择的链接。
  • work(工做):用于工做区。你能够基本相信网络内的其它计算机不会危害你的计算机。仅仅接收通过选择的链接。
  • home(家庭):用于家庭网络。你能够基本信任网络内的其它计算机不会危害你的计算机。仅仅接收通过选择的链接。
  • internal(内部):用于内部网络。你能够基本上信任网络内的其它计算机不会威胁你的计算机,仅仅接收通过选择的链接。
  • trusted(信任):可接收全部的网络链接

firewalld关于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

firewalld关于service的操做

在/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
相关文章
相关标签/搜索