标签:date lob device name rip bak sed please reboot
1 #!/bin/bash 2 set -o errexit 3 4 host_name="$1" 5 interface_old_name=`ip addr|grep BROADCAST|awk ‘{print $2}‘|sed ‘s/://g‘` 6 interface_new_name="eth0" 7 ipaddr=`ip addr|grep inet|grep brd|grep global|awk ‘{print $2}‘|grep -Eo ‘([0-9]{1,3}\.){3}[0-9]{1,3}‘` 8 netmask="255.255.255.0" 9 gateway="`ip addr|grep inet|grep brd|grep global|awk ‘{print $2}‘|grep -Eo ‘([0-9]{1,3}\.){3}‘`2" 10 11 12 13 #hostname 14 if [[ -n ${host_name} ]];then 15 echo "${host_name}" > /etc/hostname 16 else 17 echo "please input $1..." 18 exit 4 19 fi 20 21 # grub 22 set flag=0 23 grep -e "net.ifnames=0" /etc/default/grub > /dev/null 2>&1 || flag=1 24 if [ ${flag} -ne 0 ];then 25 s=`grep GRUB_CMDLINE_LINUX /etc/default/grub` 26 s2="${s%\"*} net.ifnames=0 biosdevname=0\"" 27 sed -i "s#GRUB_CMDLINE_LINUX=.*#${s2}#g" /etc/default/grub 28 grub2-mkconfig -o /boot/grub2/grub.cfg 29 unset s 30 unset s2 31 flag=0 32 fi 33 34 #修改网卡名,并配置 35 mv /etc/sysconfig/network-scripts/ifcfg-${interface_old_name} /etc/sysconfig/network-scripts/ifcfg-${interface_old_name}.bak || true 36 cat > /etc/sysconfig/network-scripts/ifcfg-${interface_new_name} << EOF 37 TYPE="Ethernet" 38 PROXY_METHOD="none" 39 BOOTPROTO="static" 40 NAME="${interface_new_name}" 41 DEVICE="${interface_new_name}" 42 ONBOOT="yes" 43 IPADDR="${ipaddr}" 44 GATEWAY="${gateway}" 45 NETMASK="${netmask}" 46 DNS1=8.8.8.8 47 EOF 48 49 #disable networkmanager 50 systemctl stop NetworkManager || true 51 systemctl disable NetworkManager || true 52 sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config 53 54 yum -y update 55 echo "10s aftre reboot..." 56 sleep 10 57 58 reboot
标签:date lob device name rip bak sed please reboot
原文地址:https://www.cnblogs.com/zhj5551/p/11198330.html