< 返回新聞公共列表

linux怎么開啟和關(guān)閉防火墻?

發(fā)布時間:2023-03-28 15:18:33

這篇文章主要介紹“linux怎么開啟和關(guān)閉防火墻?”,在日常操作中,相信很多人在linux開啟和關(guān)閉防火墻的方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!


linux怎么開啟和關(guān)閉防火墻?.jpg


在linux中,可以使用“chkconfig iptables on;”命令來永久開啟防火墻,使用“chkconfig iptables off;”命令來永久關(guān)閉防火墻,這兩個命令都是重啟后生效。


本教程操作環(huán)境:CentOS 6系統(tǒng)、Dell G3電腦。永久開啟和關(guān)閉防火墻

開啟:chkconfig iptables on;(重啟后生效)

關(guān)閉:chkconfig iptables off;(重啟后生效)


一、用法詳解

命令:

chkconfig --level 2345 iptables off或者 

chkconfig iptables off

其中2345 代表“執(zhí)行等級”

等級0表示:表示關(guān)機

等級1表示:單用戶模式

等級2表示:無網(wǎng)絡(luò)連接的多用戶命令行模式

等級3表示:有網(wǎng)絡(luò)連接的多用戶命令行模式

等級4表示:不可用

等級5表示:帶圖形界面的多用戶模式

等級6表示:重新啟動


二、暫時開啟和關(guān)閉防火墻

1、service方式

查看防火墻狀態(tài):

[root@centos6 ~]# service iptables status

Iptables:未運行防火墻。

開啟防火墻(即時生效,重啟后失效):

[root@centos6 ~]# service iptables start

關(guān)閉防火墻(即時生效,重啟后失效):

[root@centos6 ~]# service iptables stop

(注意):允許某個端口通過防火墻配置

在開啟了防火墻時,做如下設(shè)置,開啟相關(guān)端口,修改 /etc/sysconfig/iptables文件,添加以下內(nèi)容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允許80端口通過防火墻

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允許3306端口通過防火墻

備注:很多網(wǎng)友把這兩條規(guī)則添加到防火墻配置的最后一行,導(dǎo)致防火墻啟動失敗,正確的應(yīng)該是添加到默認的22端口這條規(guī)則的下面。

2、iptable方式

先進入init.d目錄,命令如下:

[root@centos6 ~]# cd /etc/init.d/[root@centos6 init.d]#

然后查看防火墻狀態(tài):

[root@centos6 init.d]# /etc/init.d/iptables status

暫時關(guān)閉防火墻:

[root@centos6 init.d]# /etc/init.d/iptables stop

重啟iptables:

[root@centos6 init.d]# /etc/init.d/iptables restart


以上就是“l(fā)inux開啟和關(guān)閉防火墻”的方法。


/template/Home/Zkeys724/PC/Static