centos6.5查看SELinux状态及关闭

本文详细介绍了如何使用getenforce和sestatus命令查看SELinux状态,包括防火墙的策略和运行模式。同时,提供了两种关闭SELinux的方法,一是临时关闭,通过setenforce0命令实现;二是永久关闭,需修改配置文件并重启系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.查看selinux的状态

  • getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反
  • setenforce 命令则是单词set(设置)和enforce(执行)连写,用于设置selinux防火墙状态,如: setenforce 0用于关闭selinux防火墙,但重启后失效
[root@localhost ~]# getenforce
Enforcing

sestatus:
查看当前系统上面SELinux的策略,运行模式等信息

[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

SELinux status:selinux防火墙的状态,enabled表示启用selinux防火墙
Current mode: selinux防火墙当前的安全策略,enforcing 表示强

2.关闭SElinux

2.1 临时关闭(不用重启即可生效)

setenforce 0 :用于关闭selinux防火墙,但重启后失效
[root@localhost ~]# setenforce 0

[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

setenforce 0 ##设置SELinux 成为permissive模式

2.2 SElinux的三种模式

  • enforcing:强制模式:代表 SELinux 运作中,且已经正确的开始限制 domain/type 了
  • permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制
  • disabled:关闭:SELinux 并没有实际运作

2.3 永久关闭SELinux(需重启生效)

打开selinux配置文件
[root@localhost ~]# vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled,保存后退出

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

重启
root@localhost ~]# reboot

验证状态

[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 disabled
 
[root@localhost ~]# getenforce
Disabled

至此 selinux关闭完成

Linux中的MAC80211和CFG80211是用于无线网络的子系统。它们提供了一组API,使开发人员能够在Linux内核中实现无线网络设备驱动程序。 MAC80211是一个实现IEEE 802.11标准的软件模块,它负责管理Linux内核中的无线网络设备。它为网络设备提供了一组接口,使它们能够与其他网络设备进行通信。MAC80211还负责处理无线帧和管理无线网络的连接。 CFG80211是一个用于配置802.11设备的API。它负责管理无线网络设备的配置,例如频率、信道和加密设置等。它还提供了一组接口,使用户空间应用程序能够与无线网络设备进行通信。 示例代码: 以下代码展示了如何使用CFG80211 API在Linux内核中配置无线网络设备。 ``` #include <linux/module.h> #include <linux/kernel.h> #include <linux/netdevice.h> #include <linux/wireless.h> #include <net/cfg80211.h> static struct cfg80211_ops my_cfg_ops = { .change_beacon = NULL, }; static struct cfg80211_device my_cfg_device = { .ops = &my_cfg_ops, }; static int __init my_init(void) { int ret; struct wireless_dev *wdev; wdev = kzalloc(sizeof(*wdev), GFP_KERNEL); if (!wdev) return -ENOMEM; wdev->wiphy = wiphy_new(&my_cfg_ops, sizeof(*wdev)); if (!wdev->wiphy) { kfree(wdev); return -ENOMEM; } wdev->wiphy->privid++; wdev->wiphy->dev.parent = NULL; wdev->wiphy->dev.release = NULL; wdev->wiphy->dev.groups = NULL; wdev->wiphy->dev.dma_mask = NULL; wdev->wiphy->dev.coherent_dma_mask = ~0; ret = wiphy_register(wdev->wiphy); if (ret) { wiphy_free(wdev->wiphy); kfree(wdev); return ret; } wdev->wiphy->dev.parent = wiphy_dev(wdev->wiphy); wdev->netdev = alloc_netdev_mqs(sizeof(struct net_device *), "my_dev", NET_NAME_UNKNOWN, ether_setup, 1, 1); if (!wdev->netdev) { wiphy_unregister(wdev->wiphy); wiphy_free(wdev->wiphy); kfree(wdev); return -ENOMEM; } wdev->wiphy->privid++; wdev->netdev->ieee80211_ptr = wdev; wdev->netdev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION; wdev->netdev->ieee80211_ptr->flags |= IEEE80211_STA_CONNECTION_POLL; ret = register_netdev(wdev->netdev); if (ret) { free_netdev(wdev->netdev); wiphy_unregister(wdev->wiphy); wiphy_free(wdev->wiphy); kfree(wdev); return ret; } my_cfg_device.wiphy = wdev->wiphy; ret = cfg80211_register_device(&my_cfg_device); if (ret) { unregister_netdev(wdev->netdev); free_netdev(wdev->netdev); wiphy_unregister(wdev->wiphy); wiphy_free(wdev->wiphy); kfree(wdev); return ret; } return 0; } static void __exit my_exit(void) { cfg80211_unregister_device(&my_cfg_device); unregister_netdev(wdev->netdev); free_netdev(wdev->netdev); wiphy_unregister(wdev->wiphy); wiphy_free(wdev->wiphy); kfree(wdev); } module_init(my_init); module_exit(my_exit); MODULE_LICENSE("GPL"); ``` 这段代码首先创建了一个无线设备和一个无线网络接口。然后,它将无线设备注册到CFG80211子系统中,并将无线网络接口注册到Linux内核中。最后,它将无线设备和无线网络接口添加到一个数据结构中,并将该数据结构注册到CFG80211子系统中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值