1. 程式人生 > >CentOS 7 關閉防火牆及 SELinux

CentOS 7 關閉防火牆及 SELinux

CentOS 7 的 SELinux 及 Firewalld 防火牆都是安全相關的套件, RHEL 及 CentOS 均預設開啟, 但如果在開發或測試的機器上, 將它們關閉對除錯方便不少。

下面的文章是教如何關閉防火牆。

關閉 SELinux:

開啟檔案 /etc/selinux/config:

# vi /etc/selinux/config

找到以下一行:

SELINUX=enforce

改成:

SELINUX=disabled

另外將 “SELINUXTYPE=targeted” 加上註釋, 改成這樣:

# SELINUXTYPE=targeted

儲存後離開編輯器, 需要重新開機設定才會生效。

要檢查 SELinux 的狀態, 執行 sestatus 指令便可以看到:

# sestatus

關閉 Firewalld 防火牆:

關閉 Firewalld 防火牆指令:

# systemctl stop firewalld.service

設定下次開機不會啟動 Firewalld 防火牆

# systemctl disable firewalld.service

SELinux 在 Redhat 及 CentOS 預設會開啟 SELinux, 要關閉 SELinux 可以用以下方法:

檢查 SELinux 的狀態

# getenforce

如果上面的結果是 Enforcing, 即 SELinux 正在執行; Permissive 是臨時關閉; 如果是 Disabled, 即已經關閉.

暫時關閉 SELinux

# setenforce 0

這樣會暫時關閉 SELinux, 無需重新開機, 但下次重新開機後 SELinux 會照常執行.

永久關閉 SELinux
開啟 /etc/sysconfig/selinux, 找到 SELINUX=enforcing, 替換為:

SELINUX=disabled

儲存檔案後重新啟動系統便會永久關閉 SELinux.