#linux#centos7关闭防火墙

centos7关闭防火墙

命令行操作

执行:

systemctl stop firewalld
systemctl disable firewalld

修改:/etc/selinux/config中,SELINUX=disabled

执行:

sed -i "s#SELINUX=.*#SELINUX=disabled#g" /etc/selinux/config
setenforce 0

shell函数

以上操作如果在shell脚本中执行,用以下函数:

function CloseFirwall()
{
    systemctl stop firewalld;
    systemctl disable firewalld;
    setenforce 0;
    if [ $(grep -c "SELINUX=e" /etc/selinux/config) != 0 ]; then
        sed -i 's#SELINUX=e.*#SELINUX=disabled#g' /etc/selinux/config;
    fi;
    if [ $(grep -c "SELINUX=p" /etc/selinux/config) != 0 ]; then
        sed -i 's#SELINUX=p.*#SELINUX=disabled#g' /etc/selinux/config;
    fi;
}

规整为一行如下:

function CloseFirwall() { systemctl stop firewalld; systemctl disable firewalld; setenforce 0; if [ $(grep -c "SELINUX=e" /etc/selinux/config) != 0 ]; then sed -i 's#SELINUX=e.*#SELINUX=disabled#g' /etc/selinux/config; fi; if [ $(grep -c "SELINUX=p" /etc/selinux/config) != 0 ]; then sed -i 's#SELINUX=p.*#SELINUX=disabled#g' /etc/selinux/config; fi; }

你可能感兴趣的:(linux)