1. 程式人生 > 實用技巧 >redhat / centos開啟關閉防火牆

redhat / centos開啟關閉防火牆

(一)redhat6/centos6
在redhat6/centos6中,Linux預設的防火牆是iptables,啟動與關閉方式如下:

#檢視防火牆狀態
service iptables status 

#臨時開啟,重啟機器後失效
service iptables start 
#臨時關閉,重啟機器後失效 
service iptables stop

#開機自啟動
chkconfig iptables on 
#關閉開機自啟動
chkconfig iptables off

對於單個埠的管理,例如要允許訪問防火牆上的埠80 ,請附加以下規則:

# iptables -A INPUT -p tcp -m tcp --dport 80
-j ACCEPT

(二)redhat7/centos7
在redhat7/centos7中,Linux預設的防火牆是firewalld,啟動與關閉方式如下:

#檢視防火牆狀態
firewall-cmd --state 
systemctl status firewalld

#臨時開啟,重啟機器後失效 
systemctl unmask firewalld 
systemctl start firewalld 

#臨時關閉,重啟機器後失效 
systemctl stop firewalld

#開機自啟動 
systemctl enable firewalld

#關閉開機自啟動
systemctl disable firewalld


# 要確保通過訪問firewalld D
-Bus介面以及如果需要其他服務也未 # 啟動firewalld firewalld,使用root輸入以下命令: systemctl mask firewalld