Linux Shell脚本_关闭防火墙

① 脚本编写
创建脚本

vim closeFirewall.sh

添加脚本内容如下:

if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then
    systemctl stop firewalld
    systemctl disable firewalld
elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then
    service iptables stop
    chkconfig iptables off
fi

保存退出:wq
② 运行脚本

chmod u+x closeFirewall.sh
./closeFirewall.sh
或者
bash closeFirewall.sh

③ 脚本内容简述

这是一个centos7和centos6 2个版本防火墙脚本
先去查看/etc/redhat-release文件中的系统版本内容,然后用正则表达式区配7.x还是6.x,然后使用管道命令过滤,最后,针对不同系统走不同分支
发布了976 篇原创文章 · 获赞 151 · 访问量 25万+

猜你喜欢

转载自blog.csdn.net/weixin_40816738/article/details/105244851