CentOS 8 的 SELinux 及 Firewalld 防火牆都是安全相關的套件, RHEL 及 CentOS 均預設開啟, 一般情況下開啟防火牆可以防止未知的服務開啟埠號, 但如果在開發或測試的機器上, 將它們關閉對除錯方便不少, 以下是在 CentOS 8 關閉防火牆及 SELinux 的方法。
檢查 SELinux 是否開啟
執行 sestatus 指令可以檢視目前 SELinux 的狀態, 其中一項是是否有開啟, 執行以下指令:
# sestatus | grep status
如果看到 enabled 表示開啟, disabled 表示關閉.
關閉 SELinux:
執行以下指令關閉 SELinux:
# setenforce 0
這樣便會把 SELinux 暫時關閉, 下次重新開機後會自動重新開啟.
如果需要下次開機後還會關閉, 需要編輯檔案 /etc/selinux/config:
# vi /etc/selinux/config
找到以下一行:
SELINUX=enforce
改成:
SELINUX=disabled
另外將 “SELINUXTYPE=targeted” 加上註釋, 改成這樣:
# SELINUXTYPE=targeted
儲存後離開編輯器, 下次重新開機後 SELinux 也會關閉。
關閉 Firewalld 防火牆:
Firewalld 是 RHEL 及 CentOS 預設的防火牆, 只要用 systemctl 便可關閉及停用:
關閉 Firewalld 防火牆:
# systemctl stop firewalld.service
設定下次開機不會啟動 Firewalld 防火牆:
# systemctl disable firewalld.service
補充一下:
/etc/selinux/config 裡面那行原本是 SELINUX=enforcing,不是 SELINUX=enforce