selinux内核防火墙

getenforce         ##查看状态
setenforce 0|1     ##0:permissive警告模式  1:enforcing强制模式 
enforcing          ##强制模式
permissive         ##警告模式
disabled           ##关闭模式
ls -Zd  /dream     ##查看目录的安全上下文
ls -Z   /dream/aa  ##查看文件的安全上下文


当selinux为disable状态时ls -Z会看到一个问号 我们将selinux的状态改为enforce强制状态重启机器再看


临时修改安全上下文
过程:新建一个文件并修改安全上下文,把其他目录下的文件移过来刷新目录发现移过来的的文件的安全上下文并没有改变
[root@localhost dream]# ls -Zd /var/ftp/pub/
drwxrwxr-x. root ftp system_u:object_r:public_content_t:s0 /var/ftp/pub/
[root@localhost dream]# mkdir /westos
[root@localhost dream]# ls -Zd /westos
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /westos
[root@localhost dream]# chcon -t public_content_t /westos  ##改变westos的安全上下文
[root@localhost dream]# ls -Zd /westos
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 /westos
[root@localhost dream]# touch /mnt/file1
[root@localhost dream]# ls -Z /mnt/file1 
-rw-r--r--. root root unconfined_u:object_r:mnt_t:s0   /mnt/file1
[root@localhost dream]# mv /mnt/file1 /westos
[root@localhost dream]# restorecon -RvvF     ##刷新安全上下文 VV显示过程
[root@localhost dream]# ls -Z /westos
-rw-r--r--. root root unconfined_u:object_r:mnt_t:s0   file1
永久修改安全上下文
[root@localhost dream]# semanage fcontext -l |grep /var/ftp/
##可以知道目录安全上下文的写法 /var/ftp/bin(/.*)?
[root@localhost dream]# semanage fcontext -a -t public_content_t '/westos'
##永久更改安全上下文
[root@localhost dream]# restorecon -RvvF /westos/
restorecon reset /westos context unconfined_u:object_r:public_content_t:s0->system_u:object_r:public_content_t:s0
restorecon reset /westos/file1 context unconfined_u:object_r:mnt_t:s0->system_u:object_r:default_t:s0
[root@localhost dream]# restorecon -RvvF  ##刷新安全上下文,临时修改刷新后不生效
[root@localhost dream]# ls -Z /westos/  ##可以发现从其他地方来的文件安全上下文也和目录一致拉
-rw-r--r--. root root system_u:object_r:default_t:s0   file1
在enforcing的条件下匿名用户ftp上传文件
1.首先要给默认发布目录的ftp组和权限
chgrp ftp /var/ftp/pub/
chmod 775 /var/ftp/pub/
2.查看并修改布尔值
getsebool -a|grep ftp
setsebool -P ftpd_anon_write on
3.将默认发布目录改为读写
chcon -t public_content_rw_t /var/ftp/pub/
当出现错误时我们可以通过查看系统日志找出问题
如果系统下安装了setroubleshoot-sercver软件时系统日志会报错并指出解决方案
可以考虑
rpm -qa |grep setrouble
yum remove setroubleshoot-server-3.2.17-2.el7.x86_64     ###卸载内核分析软件
cat /var/log/message
当没有安装时这里会显示出错信息
cat /var/log/audit/audit.log
改变服务端口
vim /etc/httpd/conf/httpd.conf 
  41 #Listen 12.34.56.78:80
  42 Listen 6666
 [root@dream /]# systemctl restart httpd                 ###发现服务起不来,看日志报错
 Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.
 semanage port -l | grep http                            ###发现端口6666不再使用范围中
 semanage port -a -t http_cache_port_t -p tcp 6666
 systemctl restart httpd                                 ###发现可以启动


 

猜你喜欢

转载自blog.csdn.net/qq_41636653/article/details/81734653