[root@localhost ~]# setenforce 0 # 临时关闭
setenforce: SELinux is disabled
[root@localhost ~]# getenforce # 查看selinux
Disabled
[root@localhost ~]# vim /etc/selinux.conf
# 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=disabled
# 永久关闭selinux
# 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 ~]# service iptables save # 保存规则
iptables: Saving firewall rules to /etc/sysconfig/iptables: [ 确定 ]
[root@localhost ~]# iptables-save > iptables.ipt
[root@localhost ~]# ls
anaconda-ks.cfg CentOS7-Base-163.repo iptables python36-3.6.3-7.el7.x86_64.rpm python36-libs-3.6.3-7.el7.x86_64.rpm
[root@localhost ~]# iptables-restore < iptables.ipt # 恢复规则
[root@localhost ~]#
firewalld
当CentOS7之后默认就没有iptables,取而代之的是firewalld。
[root@localhost ~]# systemctl enable firewalld # 开机启动
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@localhost ~]# systemctl disable firewalld # 开机关闭
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl start firewalld # 启动firewalld
[root@localhost ~]# systemctl stop firewalld # 关闭firewalld
[root@localhost ~]# systemctl restart firewalld # 重启firewalld
firewalld不再是iptables的表,而是zones
[root@localhost ~]# firewall-cmd --get-zones # 查看所有zones
block dmz drop external home internal public trusted work
[root@localhost ~]# firewall-cmd --get-default-zone # 默认zone
public
[root@localhost ~]#