Linux 防火墙和SELinux的开启和关闭

时间:2022-08-28 23:45:45

防火墙(firewalld)

  • 临时关闭防火墙
    systemctl stop firewalld
  • 永久防火墙开机自关闭
    systemctl disable firewalld
  • 临时打开防火墙
    systemctl start firewalld
  • 防火墙开机启动
    systemctl enable firewalld
  • 查看防火墙状态
    systemctl status firewalld
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: ena bled)
Active: active (running) since Sat 2017-04-08 10:36:57 CST; 31s ago
Main PID: 2856 (firewalld)
CGroup: /system.slice/firewalld.service
└─2856 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 08 10:36:56 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewal....
Apr 08 10:36:57 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall....
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#

SELinux

  • 临时关闭SELinux
    setenforce 0
  • 临时打开SELinux
    setenforce 1
  • 查看SELinux状态
    getenforce
  • 开机关闭SELinux
    编辑/etc/selinux/config文件,如下图,将SELINUX的值设置为disabled。下次开机SELinux就不会启动了。
    Linux 防火墙和SELinux的开启和关闭

注意,此时也不能通过setenforce 1命令临时打开。

[root@localhost ~]# setenforce 1
setenforce: SELinux is disabled

需要修改配置文件,然后重启linux后,才可以再打开SELinux