首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

SELinux入门:了解和配置SELinux(2)

SELinux入门:了解和配置SELinux(2)

2. 让 Apache 侦听非标准端口
默认情况下 Apache 只侦听 80 和 443 两个端口,若是直接指定其侦听 888 端口的话,会在 service httpd restart  的时候报错:
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:888(13)Permission denied: make_sock: could not bind to address 0.0.0.0:888no listening sockets available, shutting downUnable to open logs这个时候,若是在桌面环境下 SELinux 故障排除工具应该已经弹出来报错了。若是在终端下,可以通过查看 /var/log/messages  日志然后用sealert -l 加编号的方式查看,或者直接使用 sealert -b 浏览。无论哪种方式,内容和以下会比较类似:
SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 888.***** Plugin bind_ports (92.2 confidence) suggests *************************If you want to allow /usr/sbin/httpd to bind to network port 888Then you need to modify the port type.Do# semanage port -a -t PORT_TYPE -p tcp 888`where PORT_TYPE is one of the following: ntop_port_t, http_cache_port_t, http_port_t.`***** Plugin catchall_boolean (7.83 confidence) suggests *******************If you want to allow system to run with NISThen you must tell SELinux about this by enabling the 'allow_ypbind' boolean.Dosetsebool -P allow_ypbind 1***** Plugin catchall (1.41 confidence) suggests ***************************If you believe that httpd should be allowed name_bind access on the port 888 tcp_socket by default.Then you should report this as a bug.You can generate a local policy module to allow this access.Doallow this access for now by executing:# grep httpd /var/log/audit/audit.log | audit2allow -M mypol# semodule -i mypol.pp可以看出 SELinux 根据三种不同情况分别给出了对应的解决方法。在这里,第一种情况是我们想要的,于是按照其建议输入:
semanage port -a -t http_port_t -p tcp 888之后再次启动 Apache 服务就不会有问题了。
这里又可以见到 semanage 这个 SELinux 管理配置工具。它第一个选项代表要更改的类型,然后紧跟所要进行操作。详细内容参考 Man  手册
3. 允许 Apache 访问创建私人网站
若是希望用户可以通过在 ~/public_html/ 放置文件的方式创建自己的个人网站的话,那么需要在 Apache 策略中允许该操作执行。使用:
setsebool httpd_enable_homedirs 1setsebool 是用来切换由布尔值控制的 SELinux 策略的,当前布尔值策略的状态可以通过 getsebool 来获知。
默认情况下 setsebool 的设置只保留到下一次重启之前,若是想永久生效的话,需要添加 -P 参数,比如:
setsebool -P httpd_enable_homedirs 1总结
希望通过这一个简短的教程,扫除您对 SELinux 的误解甚至恐惧,个人感觉它并不比 iptables 策略复杂。如果希望您的服务器能有效抵挡 0-day  攻击时,那么 SELinux 或许就是一个值得考虑的缓和方案。
继承事业,薪火相传
返回列表