关闭防火墙命令(CentOS/Redhat/SUSE/BCLinux)

本文提供了一段用于Redhat/CentOS 5.x、6.x及7.x系列平台的脚本,该脚本能够自动检测当前系统版本,并根据版本信息关闭防火墙服务,包括iptables和firewalld,确保系统安装过程不受防火墙限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

待重新整理

脚本命令

# 安装前校验
release=`uname -r | grep -E "el5|.el6.|.el7.|default"`
#release=`cat /etc/*release 2>/dev/null | uniq | sed 's#(.*##g' | grep -E "release 6.|release 7."`
if [ "$release"x = ""x ]; then
  echo [ERROR] "Installer only support Redhat/CentOS 5.X/6.x/7.x serial platforms. Aborting..."
  exit 1
fi

# 获取版本
release_version=`uname -r | grep -Eo "el5|el6|el7|default"`

# 关闭防火墙
iptables_set()
{

case $release_version in
  "el5")
  service iptables stop
  chkconfig iptables off
  echo "el5 config firewalld success"
  ;;
  "el6")
  service iptables stop
  chkconfig iptables off
  echo "el6 config firewalld success"
  ;;
  "el7")
  systemctl stop firewalld
  systemctl disable firewalld
  echo "el7 config firewalld success"
  ;;
  "default")
  SLES_VERSION=$(sed -n '/^VERSION/ p ' /etc/*release | awk -F= '{print $2}')
  echo "SLES version is $SLES_VERSION"

  # sles11
  if [[ $SLES_VERSION =~ 11 ]]
  then
    # 取消开机启动防火墙
    chkconfig SuSEfirewall2_init off
    chkconfig SuSEfirewall2_setup off

    # 关闭操作为:
    service SuSEfirewall2_setup stop
    service SuSEfirewall2_init stop

    echo "suse11 system config firewalld success"
  fi

  # sles12
  if [[ $SLES_VERSION =~ 12 ]]
  then
    # 取消开机启动防火墙
    systemctl disable SuSEfirewall2.service

    # 关闭操作为:
    systemctl stop SuSEfirewall2.service

    echo "suse12 system config firewalld success"
  fi
  ;;
  *)
  echo [ERROR] "iptables_set unsupport release version $release_version."
  exit 1
  ;;
esac

echo "iptables_set success"
echo -e "============================================================================================================================\n"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值