CentOS 7 關閉防火牆及 SELinux
阿新 • • 發佈:2018-12-27
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.serviceSELinux 在 Redhat 及 CentOS 預設會開啟 SELinux, 要關閉 SELinux 可以用以下方法:
檢查 SELinux 的狀態
# getenforce如果上面的結果是 Enforcing, 即 SELinux 正在執行; Permissive 是臨時關閉; 如果是 Disabled, 即已經關閉.
暫時關閉 SELinux
# setenforce 0這樣會暫時關閉 SELinux, 無需重新開機, 但下次重新開機後 SELinux 會照常執行.
永久關閉 SELinux
開啟 /etc/sysconfig/selinux, 找到 SELINUX=enforcing, 替換為:
SELINUX=disabled
儲存檔案後重新啟動系統便會永久關閉 SELinux.