在CentOS中应用SELinux策略,首先要安装相关软件包,可使用命令sudo yum install -y policycoreutils selinux-policy selinux-policy-targeted
。然后通过编辑/etc/selinux/config
文件设置模式,如将SELINUX=disabled
改为SELINUX=enforcing
来启用强制模式,需重启系统生效。也可使用setenforce
命令临时切换模式。
对于特定服务策略配置,以Apache为例,可安装Apache后,用sudo chcon -R --reference=/var/www/html /path/to/your/web/directory
设置文件安全上下文。还可使用semanage
命令管理策略模块,如sudo semanage port -a -t http_port_t -p tcp 80
允许HTTP服务访问网络。