剛使用centos7會發現,用以前的方式檢視、開啟和關閉防火牆都無效了。這是因爲centos7的防火牆改用
firewalld,而不再使用
iptables了。下面就介紹
centos7怎麼檢視、開啟和關閉防火牆。
操作方法
(01)首先輸入用戶名和密碼進入centos7。
(02)接着先是看centos7的防火牆的狀態,檢視的命令爲sudo systemctl status firewalld。檢視後,看到active(running)就意味着防火牆開啟了。
(03)如果想關閉防火牆,命令爲:sudo systemctl stop firewalld。關閉後檢視是否關閉成功,如果看到inactive(dead)就意味着防火牆關閉了。
(04)開啟防火牆的命令爲:sudo systemctl start firewalld。
(05)上面開啟和關閉防火牆都是臨時的,重啓電腦後又會恢復到默認的狀態(我的默認狀態是開啟)。如圖,我先關閉了防火牆,然後輸入reboot重啓centos7。
(06)重啓後檢視防火牆狀態,還是處於開啟的狀態。
(07)如果是想重啓後防火牆還是處於關閉的狀態,得使用命令:sudo systemctl disable firewalld。
(08)輸入上一步的命令後,關閉防火牆,然後重啓。
(09)重啓後再次檢視防火牆狀態,這時防火牆就是處於關閉狀態了。
(10)最後總結一下:檢視防火牆的狀態的命令爲:sudo systemctl status firewalld。開啟防火牆的方式有兩種,一種是開啟後重啓會恢復回原來的狀態,命令爲:sudo systemctl start firewalld;另一種是開啟後重啓不會恢復到原來的狀態,命令爲:sudo systemctl enable firewalld,這種方式輸入命令後要重啓系統纔會生效。關閉防火牆的方式也有兩種,和開啟相對應,命令分別爲sudo systemctl stop firewalldsudo systemctl disable firewalld。