Centos7_防火牆的經常使用配置(雜記)

Centos6和Centos7防火牆的區別

1 使用的工具不同,Centos6使用的是Iptables而Centos7使用的則是Firewall
2 Iptables,用於過濾數據包,屬於網絡層防火牆
3 Firewall,容許那些服務可用,那些端口可用,屬於更高一層的防火牆

Firewall基本操做

systemctl start firewalld  //啓動防火牆服務

systemctl stop firewalld  //中止防火牆服務

 systemctl restart firewalld   //重啓防火牆服務

 

systemctl enable firewalld  //開機自啓動防火牆服務

systemctl disable firewalld  //禁止防火牆服務開機自啓動

systemctl is-enabled firewalld.service;echo $?  //檢查防火牆是否開機自啓動

firewall-cmd --state  //查看防火牆的狀態

 firewall-cmd --list-all  //查看防火牆規則

Firewall高級操做

參數解釋:linux

  
1 firewall-cmd:linux提供操做firewall的命令行工具
2 --add-service=協議:防火牆添加一條容許某協議的規則
3 --add-port=端口號/TCP:防火牆添加一條容許某端口號訪問的規則
4 --remove-service=協議:防火牆刪除一條容許某協議的規則
5 --remove-service=端口號/TCP:防火牆刪除一條容許某端口號訪問的規則
6 --zone=做用於:指定此條規則的做用域
7 --permanent:若不指定此參數,重啓firewall後則不保留添加的規則
8 --reload:從新載入防火牆的配置文件,使防火牆的規則生效
View Code

參數實例:網絡

當咱們開啓防火牆以後,有些服務客戶端就沒有辦法進行訪問,這個時候咱們就須要開啓指定的端口或者服務tcp

firewall-cmd --add-service=http  //容許訪問HTTP服務的流量經過

firewall-cmd --add-service=ftp  //容許訪問FTP服務的流量經過

firewall-cmd --remove-service=http   //不容許訪問HTTP服務的流量經過

firewall-cmd --remove-service=ftp  //不容許訪問FTP服務的流量經過

firewall-cmd --zone=work --add-port=80/tcp  //設置防火牆規則的做用於以及容許80端口的TCP協議流量的鏈接

firewall-cmd --permanent --zone=public --add-port=21/tcp  //設置防火牆規則的做用於爲public容許經過21號端口的tcp鏈接,爲永久生效

firewall-cmd --reload  //重載防火牆配置

 

firewall-cmd --list-port  //查看在public做用域中有哪些容許的端口訪問

 Firewall切換Iptables

1:首先要中止並開機禁用Firewallide

systemctl stop friewalld

systemctl disable firewalld

2:安裝並啓用Iptables工具

3:查看Iptables的配置文件:spa

vi /etc/sysconfig/iptables  //Iptables配置文件路徑

 

相關文章
相關標籤/搜索