天天看點

iptables表的備份和恢複、firewalld的9個zone、zone操作、service操作

service iptables save

iptables-save > my.ipt

iptables-restore < my.ipt

iptables -t nat -F

iptables -t nat -nvL

iptables-restore </tmp/ipt.txt

systemctl disable iptables

systemctl stop iptables

systemctl enable firewalld

systemctl start firewalld

firewalld預設有9個zone.zone是firewalld機關

預設zone為public。每隔zone相當于一個規則集

firewall-cmd --get-zones //檢視所有zone

firewall-cmd --get-default-zone//檢視預設zone

firewall-cmd --set-default-zone=work //設定預設zone

firewall-cmd --get-default-zone //檢視預設的zone

firewall-cmd --get-zone-of-interface=eno16777728 //查指定網卡

firewall-cmd --get-zone-of-interface=eno33554960

no zone

如果後面添加的網卡no zone設定如下:

cd /etc/sysconfig/network-scripts/

把eno16777728複制一份改成eno33554960修改配置檔案。重新開機服務在加載firewalld服務

systemctl restart firewalld

firewall-cmd --zone=public --add-interface=lo //給指定網卡設定zone 

firewall-cmd --zone=dmz --change-interface=lo //針對網卡更改zone

firewall-cmd --zone=dmz --remove-interface=lo //針對網卡删除zone 

firewall-cmd --get-active-zones //檢視系統所有網卡所在的zone

firewall-cmd --get-services 檢視所有的servies(service是zone的子單元。了解為指定的一個端口)

firewall-cmd --list-services //檢視目前zone下有哪些service

firewall-cmd --zone=public --list-service //檢視public有哪些service

firewall-cmd --zone=public --add-service=http //把http增加到public zone下面(也隻是加載到記憶體裡,把配置加到配置檔案裡去)

firewall-cmd --zone=public --remove-service=http

ls /usr/lib/firewalld/zones/ //zone的配置檔案模闆

firewall-cmd --zone=public --add-service=http --permanent //更改配置檔案,之後會在/etc/firewalld/zones目錄下面生成配置檔案

需求:ftp服務自定義端口1121,需要在work zone下面放行ftp

cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services

vi /etc/firewalld/services/ftp.xml //把21改為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

本文轉自 蝦米的春天 51CTO部落格,原文連結:http://blog.51cto.com/lsxme/2046368,如需轉載請自行聯系原作者

繼續閱讀