Myluzh Blog

CentOS系统网卡名称转换脚本

发布时间: 2022-11-29 文章作者: myluzh 分类名称: Linux 朗读文章


#######自动转换网卡名称###############
#!/bin/bash
read -p "输入要修改的网卡:" NETWORK_CARD
read -p "输入转换后的网卡名称:" NEW_NETWORK_CARD
cp /etc/sysconfig/network-scripts/ifcfg-$NETWORK_CARD /etc/sysconfig/network-scripts/networkcard.bak
Oldname=NAME\=$NETWORK_CARD
Newname=NAME\=$NEW_NETWORK_CARD
sed -i "s/$Oldname/$Newname/" /etc/sysconfig/network-scripts/ifcfg-$NETWORK_CARD
Oldcard=DEVICE\=$NETWORK_CARD
Newcard=DEVICE\=$NEW_NETWORK_CARD
sed -i "s/$Oldcard/$Newcard/" /etc/sysconfig/network-scripts/ifcfg-$NETWORK_CARD
MAC_ADDR=`ip add show ${NETWORK_CARD} | grep ether | awk '{print $2}'`
echo "HWADDR=$MAC_ADDR" >> /etc/sysconfig/network-scripts/ifcfg-$NETWORK_CARD
mv /etc/sysconfig/network-scripts/ifcfg-$NETWORK_CARD /etc/sysconfig/network-scripts/ifcfg-$NEW_NETWORK_CARD
cp -r /etc/default/grub /etc/default/grub.bak
strb=\GRUB_CMDLINE_LINUX\=\"rd.lvm.lv\=centos\/root\ rd.lvm.lv\=centos\/swap\ crashkernel\=auto\ rhgb\ quiet\ net.ifnames\=0\ biosdevname\=0\"
sed -i 's/^.*GRUB_CMDLINE_LINUX/\#&/g'  /etc/default/grub
echo $strb >> /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg

标签: centos linux

发表评论