iptables規(guī)則備份和恢復(fù)
iptables規(guī)則保存,默認(rèn)保存的位置路徑:/etc/sysconfig/iptables文件里;
[root@hch ~]# service iptables save
iptables規(guī)則備份到指定路徑;
[root@hch ~]# iptables-save > /tmp/ipt.txt
iptables清空規(guī)則;
[root@hch ~]# iptables -t nat -F
iptables查看規(guī)則;
[root@hch ~]# iptables -t nat -nvL
iptables恢復(fù)規(guī)則;
[root@hch ~]# iptables-restore < /tmp/ipt.txt
firewalld的9個(gè)zone
關(guān)閉iptables;
[root@hch ~]# systemctl disable iptables
[root@hch ~]# systemctl stop iptables
打開firewalled;
[root@hch ~]#systemctl enable firewalld
[root@hch ~]# systemctl start firewalld
firewalled有兩個(gè)基礎(chǔ)概念,分別是zone和service,每個(gè)zone里面有不同的iptables規(guī)則,默認(rèn)一共有9個(gè)zone,而Centos7默認(rèn)的zone為public。
獲取系統(tǒng)所有的zone命令如下;
[root@hch ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
查看系統(tǒng)默認(rèn)的zone命令如下;
[root@hch ~]# firewall-cmd --get-default-zone
public
9個(gè)zone的簡(jiǎn)介:
drop(丟棄):任何接收的網(wǎng)絡(luò)數(shù)據(jù)包都被拋棄,沒有任何回復(fù)。僅能有發(fā)送出去的網(wǎng)絡(luò)連接。
block(限制):任何接收的網(wǎng)絡(luò)連接都被IPv4的icmp-host-prohibited信息和IPv6的icmp-adm-prohibited信息所拒絕。
public(公共):在公共區(qū)域使用,不能相信網(wǎng)絡(luò)內(nèi)的其他計(jì)算機(jī)不會(huì)對(duì)你的計(jì)算機(jī)造成危害,只能接收經(jīng)過選取的連接
external(外部):特別是為路由器啟用了偽裝功能的外部網(wǎng)。你不能信任來自網(wǎng)絡(luò)的其他計(jì)算,不能相信它們不會(huì)對(duì)你的計(jì)算機(jī)造成危害,只能接收經(jīng)過選擇的連接。
dmz(非軍事區(qū)):用于你的非軍事區(qū)內(nèi)的計(jì)算機(jī),此區(qū)域內(nèi)可公開訪問,可以有限地進(jìn)入你的內(nèi)部網(wǎng)絡(luò),僅僅接收經(jīng)過選擇的連接。
work(工作):用于工作區(qū)。你可以基本相信網(wǎng)絡(luò)內(nèi)的其它計(jì)算機(jī)不會(huì)危害你的計(jì)算機(jī)。僅僅接收經(jīng)過選擇的連接。
home(家庭):用于家庭網(wǎng)絡(luò)。你可以基本信任網(wǎng)絡(luò)內(nèi)的其它計(jì)算機(jī)不會(huì)危害你的計(jì)算機(jī)。僅僅接收經(jīng)過選擇的連接。
internal(內(nèi)部):用于內(nèi)部網(wǎng)絡(luò)。你可以基本上信任網(wǎng)絡(luò)內(nèi)的其它計(jì)算機(jī)不會(huì)威脅你的計(jì)算機(jī),僅僅接收經(jīng)過選擇的連接。
trusted(信任):可接收所有的網(wǎng)絡(luò)連接
firewalld關(guān)于zone的操作
關(guān)于zone的命令;
[root@hch ~]#? firewall-cmd --set-default-zone=work //設(shè)定默認(rèn)的zone為work
[root@hch ~]#? firewall-cmd --get-zone-of-interface=ens33 //查看指定網(wǎng)卡所在的zone
[root@hch ~]#? firewall-cmd --zone=public --add-interface=lo //給指定網(wǎng)卡設(shè)置zone
[root@hch ~]#? firewall-cmd --zone=dmz --change-interface=lo //針對(duì)網(wǎng)卡更改zone
[root@hch ~]#? firewall-cmd --zone=dmz --remove-interface=lo //針對(duì)網(wǎng)卡刪除zone
[root@hch ~]#? firewall-cmd --get-active-zones //查看系統(tǒng)所有網(wǎng)卡所在的zone
public
interfaces: ens33
firewalld關(guān)于service的操作
[root@hch ~]#? firewall-cmd --get-services //列出當(dāng)前系統(tǒng)所有的service
[root@hch ~]#? firewall-cmd --list-services //查看當(dāng)前zone下有哪些service
[root@hch ~]#? firewall-cmd --zone=public --list-services //查看指定zone下有哪些service
[root@hch ~]#? firewall-cmd --zone=public --add-service=http //把http增加到public zone下面
[root@hch ~]#? firewall-cmd --zone=public --add-service=http --permanent //以修改配置文件來增加service
[root@hch ~]#??ls /usr/lib/firewalld/zones/ //查看zone對(duì)應(yīng)的配置文件
[root@hch ~]#? ls /etc/firewalld/zones/ //一旦更改zone配置文件,則會(huì)在這個(gè)路徑下面生成對(duì)應(yīng)的zone的配置文件
演示一個(gè)需求操作,ftp服務(wù)自定義端口1121,需要在work zone下面方行ftp
操作如下;
[root@hch ~]#? cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/?
[root@hch ~]#? vi /etc/firewalld/services/ftp.xml //把里面的21改為1121
[root@hch ~]#? cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@hch ~]#? vi /etc/firewalld/zones/work.xml //在里面增加一行FTP相關(guān)的配置,內(nèi)容如下
如此配置工作就完成,輸入以下命令重新加載
[root@hch ~]#? firewall-cmd --reload
并驗(yàn)證以下
[root@hch ~]#? firewall-cmd --zone=work --list-services
ssh dhcpv6-client ftp