Centos7 完全禁用IPV6脚本

#!/bin/bash
#del ipv6
#2019-05-29
#version 1.0
GRUPFILE='/etc/default/grub'
NETDIR='/etc/sysconfig/network-scripts'
NETNAME=`ls $NETDIR | grep 'ifcfg-'`
TCPSIX=`netstat -luntp |grep tcp6|wc -l`
IPVSIX=`grep -o "ipv6.disable" /etc/default/grub`
clear
date
#判断grub文件中是否有ipv6.disable以及tcp6是否还存在。防止多次执行脚本出现的错误。
if [[ -n $IPVSIX ]] && [[ $TCPSIX -ge 1 ]];then
   echo -e "\nIPV6 in grub file has been modified."
   echo -e "\nPlease restart the system by yourself."
   exit
fi
#检测IPV6是否被禁止
if [ $TCPSIX -eq 0 ];then
  echo "IPV6 has been disabled in your system, so you don't need to run this script anymore."
  exit
fi
#删除网卡文件里面的IPV6的行
echo "Deleting IPV6 from Network  File"
for i in $NETNAME
do
sed -i '/IPV6/d' $NETDIR/$i
done
sleep 1
echo -e "\nDelete IPV6 completed in network file."
echo -e "Modifying grub file. \n"
#修改grub.cfg文件,添加ipv6.disable=1
sed -i 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="ipv6.disable=1 /g' $GRUPFILE
#重新生成grup文件
grub2-mkconfig -o /boot/grub2/grub.cfg
sleep 1
systemctl restart network
if [ $? -ne 0 ];then
echo "Please restart your network serivces."
fi
echo -e "The grub file has been modified. Please choose whether you need to restart the system.\n"
echo -e "You have 7 seconds to choose.\n"
read -p "Please select and press Enter. (y/n): " -t 7 READY
if [[ $READY == 'y' ]];then
echo "System is restarting"
init 6
elif [[ $READY == 'n' ]];then
echo "Please restart the system by yourself."
exit
else
echo -e "\nInput error or no input. \nPlease restart the system by yourself."
exit
fi