轉至:https://blog.csdn.net/weixin_40816738/article/details/105244851
① 腳本編寫
創建腳本
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,然后使用管道命令過濾,最后,針對不同系統走不同分支