Semanage是用于配置SELinux策略某些元素而无需修改或重新编译策略源的工具。
这包括将Linux用户名映射到SELinux用户身份以及对象(如网络端口,接口和主机)的安全上下文映射。
Semanage是用于配置SELinux策略某些元素而无需修改或重新编译策略源的工具。 这包括将Linux用户名映射到SELinux用户身份以及对象(如网络端口,接口和主机)的安全上下文映射。
Selinux已经开启
开启方式:
[root@localhost ~]# semanage port -l
SELinux Port Type Proto Port Number
afs3_callback_port_t tcp 7001
afs3_callback_port_t udp 7001
afs_bos_port_t udp 7007
afs_fs_port_t tcp 2040
列出指定的端口类型的端口:
[root@localhost ~]# semanage port -l|grep -w 53
dns_port_t tcp 53
dns_port_t udp 53
[root@localhost ~]# semanage port -l|grep -w 20
ftp_data_port_t tcp 20
[root@localhost ~]# semanage port -l|grep -w 21
ftp_port_t tcp 21, 989, 990
创建、添加、修改端口
通过下面的命令为http添加新端口
[root@localhost ~]#
[root@localhost ~]# semanage port -a -t http_port_t -p tcp 8888
[root@localhost ~]#
[root@localhost ~]# semanage port -l|grep -w 8888
http_port_t tcp 8888, 80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@localhost ~]# semanage port -lC
SELinux Port Type Proto Port Number
http_port_t tcp 8888
为samba共享目录添加安全上下文
[root@localhost ~]# ll -dZ /share/
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /share/
[root@localhost ~]# semanage fcontext -a -t samba_share_t ‘/share(/.*)?‘
[root@localhost ~]# restorecon -Rv /share
restorecon reset /share context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0
[root@localhost ~]# ll -dZ /share
drwxr-xr-x. root root unconfined_u:object_r:samba_share_t:s0 /share
为nfs共享目录添加读写
[root@localhost ~]# ll -dZ /nfsshare/
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /nfsshare/
[root@localhost ~]#
[root@localhost ~]# semanage fcontext -a -t public_content_rw_t ‘/nfsshare(/.*)?‘
[root@localhost ~]# restorecon -Rv /nfsshare
[root@localhost ~]# ll -dZ /nfsshare/
drwxr-xr-x. root root unconfined_u:object_r:public_content_rw_t:s0 /nfsshare/
本文讲述了添加、修改和删除端口,修改安全上下文。如果你的系统有安装桌面,可以安装图形化管理软件 policycoreutils-gui来进行管理。
[root@localhost ~]# yum -y install policycoreutils-gui
[root@localhost ~]# system-config-selinux
原文:https://www.cnblogs.com/yyuuee/p/14252943.html