<1>SELinux 模式
並非所有 Linux distributions 都支援 SELinux, 目前 SELinux 支援三種模式, 分別如下:
*enforcing(強制模式), 代表 SELinux 運作中, 且已經正確的開始限制 domain/type 了;
 
*permissive(寬容模式), 代表 SELinux 運作中, 不過僅會有警告訊息並不會實際限制 domain/type 的存取, 這種模式可以用來作為 SELinux 的 debug 之用;
 
*disabled(關閉),SELinux 並沒有實際運作;
 
<2>檢視 SELinux 模式
命令 : getenforce
[root@sqj ~]# getenforce
Enforcing    <==顯示當前的模式為 Enforcing   <3>檢視 SELinux 的政策 (Policy)
[root@sqj ~]# sestatus
SELinux status:          enabled
SELinuxfs mount:         /selinux  <==SELinux 的相關檔案資料掛載點 Current mode:            enforcing <==目前的模式 Mode from config file:   enforcing <==設定檔指定的模式 Policy version:          24 Policy from config file: targeted  <==目前的政策     <4>透過配置檔案 (/etc/selinux/config) 調整 SELinux 的引數
[root@sqj ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing – SELinux security policy is enforced.
#     permissive – SELinux prints warnings instead of enforcing.
#     disabled – No SELinux policy is loaded.
SELINUX=enforcing   <==啟動模式 # SELINUXTYPE= can take one of these two values: #     targeted – Targeted processes are protected, #     mls – Multi Level Security protection. SELINUXTYPE=targeted  <==預設政策 注: 無論是啟動模式或預設政策修改, 都需要重啟才能生效.   <5>檢視 SELinux 狀態
命令 : /usr/sbin/sestatus -v
 
[root@sqj ~]# /usr/sbin/sestatus -v
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted
 
<6>關閉 SELinux 的方法
* 修改/etc/selinux/config 檔案中的 SELINUX=”” 為 disabled, 然後重啟;
 
*若不想重啟系統, 使用命令 setenforce 0
注:
setenforce 1 設定 SELinux 為 enforcing 模式;
setenforce 0 設定 SELinux 為 permissive 模式;
同樣, 在 grub 的啟動引數中增加 selinux=0 也可以關閉 SELinux.
 
*快速關閉 SELinux
/usr/sbin/setenforce 0 立刻關閉 SELinux
/usr/sbin/setenforce 1 立刻啟用 SELinux
可以加入系統啟動裡面
echo “/usr/sbin/setenforce 0” >>/etc/rc/local
這樣, 我們就不需要再 centos 系統中開啟 SELinux, 就可以快速關閉了, 以及在需要的時候, 再開啟它.