直接上代码!
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#!/bin/sh [ -f /etc/init.d/functions ] && . /etc/init.d/functions ###修改网卡配置文件名称 function net () { b0=-1 cat /proc/net/dev |grep ':' | grep -v 'lo' | cut -d: -f1 | sort >> /tmp/net_name.txt do c0=$line b0=`expr $b0 + 1` mv /etc/sysconfig/network-scripts/ifcfg-$c0 /etc/sysconfig/network-scripts/ifcfg-eth$b0 ##修改网卡模式为static sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-eth$b0 ##删除包含IPV6的行 sed -i '/IPV6/d' /etc/sysconfig/network-scripts/ifcfg-eth$b0 ##修改网卡DEVICE为eth. sed -i 's/'$c0'/eth'$b0'/g' /etc/sysconfig/network-scripts/ifcfg-eth$b0 done < /tmp/net_name.txt } ###重新配置grub配置并更新内核 function grub () { sed -i 's/crashkernel=auto rhgb quiet/crashkernel=auto net.ifnames=0 biosdevname=0 rhgb quiet/g' /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg } ###修改网卡创建命名规则 function rules () { b0=-1 /sbin/lspci | awk '/net/ || /less/ { print $1 }' | sort | while read line do c0=$line b0=`expr $b0 + 1` echo 'ACTION=="add", SUBSYSTEM=="net", BUS=="pci", ID=="0000:'$c0'", NAME="eth'$b0'"' >>/etc/udev/rules.d/70-persistent-net.rules done } net grub rules |
备注:此脚本未经过测试,本站不保证脚本是否有bug!SourceByrd's Weblog-https://note.t4x.org/code/centos7-changes-netwrok-card/
转载:http://yangfannie.com/949.htmlSourceByrd's Weblog-https://note.t4x.org/code/centos7-changes-netwrok-card/ SourceByrd's Weblog-https://note.t4x.org/code/centos7-changes-netwrok-card/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!