查看端口标签
semanage port –l
添加端口
semanage port -a -t port_label-p tcp|udpPORT
semanage port -a -t http_port_t -p tcp 9527
删除端口
semanage port -d -t port_label-p tcp|udpPORT
semanage port -d -t http_port_t -p tcp 9527
修改
semanage port -m -t port_label-p tcp|udpPORT
semanage port -m -t http_port_t-p tcp9527
7.布尔规则
布尔型规则:
getsebool
setsebool
查看bool命令:
getsebool [-a] [boolean]
semanage boolean –l
semanage boolean -l –C 查看修改过的布尔值
设置bool值命令:
setsebool [-P] booleanvalue
setsebool [-P] Boolean=value
8.日志
yum install setroublesshoot*(重启生效)
将错误的信息写入/var/log/message
grep setroubleshoot/var/log/messages
sealert-l UUID
查看安全事件日志说明
sealert-a /var/log/audit/audit.log
扫描并分析日志
Apache SELinux 配置实例
1、安装httpd服务,改变网站的默认主目录为/website,添加SELinux文件标签规则,设置http_sys_content_t到/website及目录下所有文件,使网站可访问
[root@~]# mkdir /website
[root@~]# ll -Z /website -d
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /websit
[root@~]# ll -Z /var/www/html/
-rw-r--r--. root root system_u:object_r:httpd_sys_content_t:s0 index.html
[root@~]# chcon --reference=/var/www/html /website
[root@~]#ll -Z /website/
-rwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/website"
[root@~]# service httpd restart
[root@~]#echo "test website" > /website/index.html
测试:
在浏览器上输入地址,可以正常访问到
2、修改网站端口为9527,增加SELinux端口标签,使网站可访问
[root@~]# semanage port -l | grep "http_port_t"
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@~]# semanage port -a -t http_port_t -p tcp 9527
[root@~]# semanage port -l | grep "http_port_t"
http_port_t tcp 9527,80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@~]#vim /etc/httpd/conf/httpd.conf
Listen 9527
测试:
3、启用SELinux布尔值,使用户student的家目录可通过http访问
[root@~]#vim /etc/httpd/conf/httpd.conf
修改为:
# UserDir disabled
UserDir public_html
[root@~]# chmod 711 /home/jay
[root@~]#mkdir /home/jay/public_html
[root@~]#echo "jay home" > /home/jay/public_html/index.html
查看布尔规则:
[root@~]# semanage boolean -l | grep "homedir"
httpd_enable_homedirs (off , off) Allow httpd to read home directories
修改布尔规则:
[root@~]# setsebool -P httpd_enable_homedirs on
测试: