linux防火牆開啟和關閉詳解
阿新 • • 發佈:2019-02-16
以下兩種方法
一、暫時開啟和關閉防火牆
1種 service方式
檢視防火牆狀態:
[[email protected] ~]# service iptables status
iptables:未執行防火牆。
開啟防火牆(即時生效,重啟後失效):
[[email protected] ~]# service iptables start
關閉防火牆(即時生效,重啟後失效):
[[email protected] ~]# service iptables stop
(注意):允許某個埠通過防火牆配置
在開啟了防火牆時,做如下設定,開啟相關埠,修改 /etc/sysconfig/iptables 檔案,新增以下內容:
-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埠通過防火牆
備註:很多網友把這兩條規則新增到防火牆配置的最後一行,導致防火牆啟動失敗,
正確的應該是新增到預設的22埠這條規則的下面
2種 iptables方式
先進入init.d目錄,命令如下:
[[email protected] ~]# cd /etc/init.d/
[[email protected] init.d]#
然後
檢視防火牆狀態:
[[email protected] init.d]# /etc/init.d/iptables status
暫時關閉防火牆:
[[email protected] init.d]# /etc/init.d/iptables stop
重啟iptables:
[[email protected] init.d]# /etc/init.d/iptables restart
二、永久開啟和關閉防火牆
開啟:chkconfig iptables on;(重啟後生效)
關閉:chkconfig iptables off;(重啟後生效)
用法詳解
命令:chkconfig --level 2345 iptables off
或者 chkconfig iptables off
其中2345 代表”執行等級“
等級0表示:表示關機
等級1表示:單使用者模式
等級2表示:無網路連線的多使用者命令列模式
等級3表示:有網路連線的多使用者命令列模式
等級4表示:不可用
等級5表示:帶圖形介面的多使用者模式
等級6表示:重新啟動
三擴充套件
安全增強型 Linux(Security-Enhanced Linux)簡稱 SELinux,它是一個 Linux 核心模組,也是 Linux 的一個安全子系統
關閉SELinux
vim /etc/selinux/config # 改為 SELINUX=disabled
# 儲存退出,重啟伺服器
init 6
禁用SeLinux
#永久禁用,需要重啟生效。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 臨時禁用,不需要重啟
setenforce 0
一、暫時開啟和關閉防火牆
1種 service方式
檢視防火牆狀態:
[[email protected] ~]# service iptables status
iptables:未執行防火牆。
開啟防火牆(即時生效,重啟後失效):
[[email protected] ~]# service iptables start
關閉防火牆(即時生效,重啟後失效):
[[email protected] ~]# service iptables stop
(注意):允許某個埠通過防火牆配置
在開啟了防火牆時,做如下設定,開啟相關埠,修改 /etc/sysconfig/iptables 檔案,新增以下內容:
-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埠通過防火牆
備註:很多網友把這兩條規則新增到防火牆配置的最後一行,導致防火牆啟動失敗,
正確的應該是新增到預設的22埠這條規則的下面
2種 iptables方式
先進入init.d目錄,命令如下:
[[email protected] ~]# cd /etc/init.d/
[[email protected] init.d]#
然後
檢視防火牆狀態:
[[email protected] init.d]# /etc/init.d/iptables status
暫時關閉防火牆:
[[email protected] init.d]# /etc/init.d/iptables stop
重啟iptables:
[[email protected] init.d]# /etc/init.d/iptables restart
二、永久開啟和關閉防火牆
開啟:chkconfig iptables on;(重啟後生效)
關閉:chkconfig iptables off;(重啟後生效)
用法詳解
命令:chkconfig --level 2345 iptables off
或者 chkconfig iptables off
其中2345 代表”執行等級“
等級0表示:表示關機
等級1表示:單使用者模式
等級2表示:無網路連線的多使用者命令列模式
等級3表示:有網路連線的多使用者命令列模式
等級4表示:不可用
等級5表示:帶圖形介面的多使用者模式
等級6表示:重新啟動
三擴充套件
安全增強型 Linux(Security-Enhanced Linux)簡稱 SELinux,它是一個 Linux 核心模組,也是 Linux 的一個安全子系統
關閉SELinux
vim /etc/selinux/config # 改為 SELINUX=disabled
# 儲存退出,重啟伺服器
init 6
禁用SeLinux
#永久禁用,需要重啟生效。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 臨時禁用,不需要重啟
setenforce 0