如何使用semanage管理SELinux安全策略
发表于:2024-10-12 作者:千家信息网编辑
千家信息网最后更新 2024年10月12日,这篇文章给大家分享的是有关如何使用semanage管理SELinux安全策略的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Semanage是用于配置SE Linux策略某些
千家信息网最后更新 2024年10月12日如何使用semanage管理SELinux安全策略
这篇文章给大家分享的是有关如何使用semanage管理SELinux安全策略的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
Semanage是用于配置SE Linux策略某些元素而无需修改或重新编译策略源的工具。 这包括将Linux用户名映射到SELinux用户身份以及对象(如网络端口,接口和主机)的安全上下文映射。 |
简介
Semanage是用于配置SELinux策略某些元素而无需修改或重新编译策略源的工具。 这包括将Linux用户名映射到SELinux用户身份以及对象(如网络端口,接口和主机)的安全上下文映射。
实验环境
Centos7.7操作系统
Selinux已经开启
开启方式:
[root@localhost ~]# sed -i '/^SELINUX/s/disabled/enforcing/g' /etc/selinux/config# 然后重启一下操作系统[root@localhost ~]# reboot# 重启完成之后检查一下是否是enforcing模式[root@localhost ~]# getenforce Enforcing
常用参数
port: 管理定义的网络端口类型
fcontext: 管理定义的文件上下文
-l: 列出所有记录
-a: 添加记录
-m: 修改记录
-d: 删除记录
-t: 添加的类型
-p: 指定添加的端口是tcp或udp协议的,port子 命令下使用
-e: 目标路径参考原路径的上下文类型,fcontext子 命令下使用
列出所有定义的端口
使用semanage port命令列出所有端口
[root@localhost ~]# semanage port -lSELinux Port Type Proto Port Numberafs3_callback_port_t tcp 7001afs3_callback_port_t udp 7001afs_bos_port_t udp 7007afs_fs_port_t tcp 2040afs_fs_port_t udp 7000, 7005afs_ka_port_t udp 7004afs_pt_port_t tcp 7002afs_pt_port_t udp 7002afs_vl_port_t udp 7003agentx_port_t tcp 705agentx_port_t udp 705amanda_port_t tcp 10080-10083amanda_port_t udp 10080-10082……
列出指定的端口类型的端口
[root@localhost ~]# semanage port -l|grep -w http_port_thttp_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
通过查询端口号来列出端口类型
[root@localhost ~]# semanage port -l|grep -w 53dns_port_t tcp 53dns_port_t udp 53[root@localhost ~]# semanage port -l|grep -w 20ftp_data_port_t tcp 20[root@localhost ~]# semanage port -l|grep -w 21ftp_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 8888http_port_t tcp 8888, 80, 81, 443, 488, 8008, 8009, 8443, 9000# 也可以使用-C参数查看自定义的端口号[root@localhost ~]# semanage port -lCSELinux Port Type Proto Port Numberhttp_port_t tcp 8888
添加一个范围的端口
[root@localhost ~]# semanage port -a -t http_port_t -p tcp 11180-11188[root@localhost ~]# [root@localhost ~]# semanage port -lCSELinux Port Type Proto Port Numberhttp_port_t tcp 8888, 11180-11188
删除端口
[root@localhost ~]# semanage port -d -t http_port_t -p tcp 8888[root@localhost ~]# [root@localhost ~]# semanage port -d -t http_port_t -p tcp 11180-11188[root@localhost ~]# # 查看一下,已经没有自定义的端口了[root@localhost ~]# semanage port -lC
修改安全上下文
为samba共享目录添加安全上下文
# 没添加安全上下文之前是default_t[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 /sharerestorecon reset /share context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0# 查看一下文件夹已经变成samba_share_t了[root@localhost ~]# ll -dZ /sharedrwxr-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# system-config-selinux执行该命令打开图形化管理界面[root@localhost ~]# system-config-selinux
感谢各位的阅读!关于"如何使用semanage管理SELinux安全策略"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
端口
安全
上下
上下文
管理
策略
命令
类型
用户
文件
系统
网络
操作系统
主机
元素
内容
参数
口号
图形
对象
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
hp服务器介绍
谷榕网络技术大数据中心项目
贵阳市网络安全周应急演练
连接数据库提示2003什么意思
粤教版网络技术
gta5r星服务器
2020年网络安全专题教育
电力网络安全
游爱网络技术有限公司面试题
贵州大学网络安全建设学院
成都手机棋牌软件开发
南京二手服务器回收电话多少
数据库怎么存放文件地址
数据库跨库查询解决方案
您不能在安全服务器上玩
动力无限网络技术有限公司
拜登网络安全教学视频
戴尔服务器武汉代理是谁
5e对战平台服务器选择
5g无线传输技术与网络技术
网络安全和信息化办公室设在
qt软件开发百度文字识别
许昌财务软件开发
森科网络技术
中国电信无线网络安全
QQ定位数据库最新版
计算机网络技术大概是学什么的
网络安全态势感知 技术
vos服务器
嵌入式移动应用软件开发