设定了的防火墙规则要进行保存,不然系统重启后这些规则就没有了,使用命令 ”service iptables save ” 会把设定好的防火墙规则保存到文件/etc/sysconfig/iptables 里。centos
也能够把设定的iptables 规则备份到/tmp/ipt.txt文件中 ,使用命令:” iptables-save >/tmp/ipt.txt ”网络
恢复备份的规则:” iptables-restore < /tmp/ipt.txt “centos7
关闭 iptables 再打开firewalld使用命令:spa
systemctl disable iptables systemctl stop iptables systemctl enable firewalld systemctl start firewalld
firewalld默认有9个zone,zone是firewalld的一个单位,每一个zone是一个规则集rest
查看全部的zone :”firewall-cmd --get-zones”xml
查询默认的zone:” firewall-cmd --get-default-zone”blog
drop(丢弃) :任何接受的网络数据包都被丢弃,没有任何回复,仅能有发送出去的网络链接ip
block(限制):任何接收的网络链接都被IPv4的icmp-host-prohibited信息和IPv6的icmp6-adm-prohibited信息拒绝路由
public(公共):在公共区域使用,不能信任来自网络的其余计算机不会危害你的计算机,解锁通过选择的链接,这个是默认的zonerem
external(外部):用于外部网络,特别是位路由器启用的假装的外部网。不能信任来自网络的其余计算机,不能相信它们不会对你的计算机形成危害,值能接收通过选择的链接
dmz(非军事区):此区域能够公开访问,能够有限地进入你的内部网络,只接收通过选择的链接
work(工做):能够基本上信任网络内的其余计算机不会危害你的计算机,仅仅接收通过选择的连接
home(家庭):家庭网络,,基本能够信任网络内的其余计算机不会危害你的计算机,接收通过选择的链接
internal(内部):内部网络,基本上信任网络内其余计算机不会危害你的计算机,只接收通过选择的链接
trusted(信任):可接收全部网络链接
设定默认zone为work:
firewall-cmd --set-default-zone=work
查指定的网卡的zone
firewall-cmd --get-zone-of-interface=ens33
给指定的网卡lo设置zone为public
firewall-cmd --zone=public --add-interface=lo
针对网卡ens33的zone更改成work:
firewall-cmd --zone=work --change-interface=ens33
查看系统全部的网卡所在的zone:
firewall-cmd --get-active-zones
services是zone下的子单元,是指定的端口,防火墙对端口进行一些限制
查看全部的service : firewall-cmd --get-service
查看指定zone的services
查看当前zone下有哪些service : firewall-cmd --list-services
把http增长到public zone下面: firewall-cmd --zone=public --add-service=http
将配置保存到配置文件里 :
firewall-cmd --zone=public --add-service=http --permanent
配置文件要在目录/etc/firewalld/zones/里寻找
firewall-cmd --zone-public --remove-service=http
zone的配置文件模板 /usr/lib/firewalld/services/
更改配置文件以后会在/etc/firewalld/zones目录下面生产能配置文件
需求:ftp服务自定义端口1121,须要在work zone下面放行ftp。
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/serwalld/services
vi /etc/firewalld/services/ftp.xml //port=后面改成1121
cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones
vi /etc/firewalld/zones/work.xml //增长下面一行进入文件里
<service name="ftp"/>
firewall-cmd --reload 从新加载
firewall-cmd --zone=work --list-services //查看work下services