linux关闭selinux防火墙的方法
SELinux是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。对于linux新手,在不会设置selinux的情况下,想要建站或者做其他行为,首先关闭它,不然什么事也做不了。
一、查看linux的selinux当前状态是开启的还是关闭的。
方法1、/usr/sbin/sestatus -v
方法2、
getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反。
setenforce 命令则是单词set(设置)和enforce(执行)连写,用于设置selinux防火墙状态,如: setenforce 0用于关闭selinux防火墙,但重启后失效
disabled表示关闭状态。
Enforcing表示开启状态。
二、 /usr/sbin/sestatus 查看selinux配置状态。
Current mode表示当前selinux防火墙的安全策略
[root@localhost ~]# /usr/sbin/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: allowedMax kernel policy version: 28
SELinux status:selinux防火墙的状态,enabled表示启用selinux防火墙
Current mode: selinux防火墙当前的安全策略,enforcing 表示强
三、关闭selinux。
1、临时关闭selinux(不用重启机器):
setenforce 0 #设置SELinux 成为permissive模式 setenforce 1 设置SELinux 成为enforcing模式
2、打开 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
此时获取当前selinux防火墙的安全策略仍为Enforcing,配置文件并未生效。
[root@localhost ~]# getenforce Enforcing
重启服务器生效
[root@localhost ~]# reboot
selinux配置文件修改成
修改完毕后必须重启服务器方能生效。