Centos 7 修改网卡名称为eth

#!/bin/bash
function chk_base()
{
clear
date
echo "########################################"
echo "#                                      #"
echo "# Centos 7 修改网卡名称 ensxx 为 eth0  #"
echo "#                                      #"
echo "########################################"
for i in `seq -w 2 -1 0`
do
echo -ne "\b\b\b\b$i 秒"
sleep 1
done
echo ""
MYVER=`cat /etc/redhat-release |awk '{print $4}'| awk -F [.] '{print $1}'`
expr 1 + $MYVER &>/dev/null
if [ $? -ne 0 ];then
echo "请在 7 版本的系统里面运行该脚本....."
exit
fi
if [ $UID -ne 0 ]; then
echo "请用 root 用户运行该脚本...."
exit
fi
}

function change_eth {
NETFILE_DIR="/etc/sysconfig/network-scripts"
NETFILE_SUM=`find $NETFILE_DIR -name "ifcfg-ens*"`
ETHFILE_SUM=`find $NETFILE_DIR -name "ifcfg-eth*"|wc -l`
if [ $ETHFILE_SUM -ge 1 ];then
echo "网卡名称已修改。"
ls $NETFILE_DIR/ifcfg-eth*
exit
else
echo "开始修改网卡名称......"
#循环修改
j=0
for i in $NETFILE_SUM
do
NETNAME=`cat $i |grep "DEVICE" |awk -F '=' '{print $2}'`
sed -i "s#$NETNAME#eth$j#g" $i
mv $i $NETFILE_DIR/ifcfg-eth$j
j=`expr $j + 1`
done
sed -i '/vmlinuz-3/ s#$# net.ifnames=0#' /boot/grub2/grub.cfg
echo "网卡名称修改完成"
echo -e "The grub file has been modified. Please restart system.\n"
echo -e "You have 5 seconds to choose.\n"
read -p "Please select and press Enter. (y/n): " -t 5 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 by yourself."
    exit
  fi
fi
}
chk_base
change_eth