除了通过配置文件可以对 SELinux 进行工作模式的修改之外,还可以使用命令查看和修改 SELinux 工作模式。
首先,查看系统当前 SELinux 的工作模式,可以使用 getenforce 命令;而如果想要查看配置文件中的当前模式和模式设置,可以使用 sestatus 命令,下面的代码显示了这两个命令:
[root@localhost ~]# getenforce#查询SELinux的运行模式Enforcing#当前的SELinux是强制模式[root@localhost ~]# sestatusSELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted
除可以查询 SELinux 的运行模式之外,也可以修改 SELinux 的运行模式,即使用 setenforce 命令。不过需要注意,setenforce 命令只能让 SELinux 在 enforcing 和 permissive 两种模式之间进行切换。
如果从启动切换到关闭,或从关闭切换到启动,则只能修改配置文件,setenforce 命令就无能为力了。
setenforce 命令的基本格式如下:
[root@localhost ~]# setenforce 选项选项: 0: 切换成 permissive(宽容模式); 1: 切换成 enforcing(强制模式);
例如:
[root@localhost ~]# setenforce 0#切换成宽容模式[root@localhost ~]# getenforcePermissive [root@localhost ~]# setenforce 1#切换成强制模式[root@localhost ~]# getenforceEnforcing