更改Linux系统的网卡名称
一、网卡配置文件名称重命名为eth0 (也可以改为其他名称)# ifconfigens33: flags=4163mtu 1500 inet 192.168.10.11netmask 255.255.255.0broadcast 192.168.10.255 inet6 fe80::250:56ff:fe29:eaeprefixlen 64scopeid 0x20 ether 00:50:56:29:0e:aetxqueuelen 1000(Ethernet) RX packets 132bytes 14492 (14.1 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 115bytes 13105 (12.7 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0lo: flags=73mtu 65536 inet 127.0.0.1netmask 255.0.0.0 inet6 ::1prefixlen 128scopeid 0x10 looptxqueuelen 1000(Local Loopback) RX packets 140bytes 11204 (10.9 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 140bytes 11204 (10.9 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0# # cd /etc/sysconfig/network-scripts/# lsifcfg-ens33ifdown-ppp ifup-eth ifup-sitifcfg-lo ifdown-routes ifup-ippp ifup-Teamifdown ifdown-sit ifup-ipv6 ifup-TeamPortifdown-bnepifdown-Team ifup-isdn ifup-tunnelifdown-eth ifdown-TeamPortifup-plip ifup-wirelessifdown-ipppifdown-tunnel ifup-plusb init.ipv6-globalifdown-ipv6ifup ifup-post network-functionsifdown-isdnifup-aliases ifup-ppp network-functions-ipv6ifdown-postifup-bnep ifup-routes# mv ifcfg-ens33 ifcfg-eth0# vim ifcfg-eth0 TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noNAME=eth0DEVICE=eth0ONBOOT=yesIPADDR=192.168.10.11GATEWAY=192.168.10.2NETMASK=255.255.255.0二、禁用网卡命名规则
此功能通过/etc/default/grub文件来控制,要禁用此功能,在文件中加入"net.ifnames=0biosdevname=0"即可# vim /etc/default/grubGRUB_TIMEOUT=5GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_TERMINAL_OUTPUT="console"GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"GRUB_DISABLE_RECOVERY="true"三、添加udev网卡规则
在/etc/udev/rules.d目录中创建一个网卡规则70-persistent-net.rules文件,在文件中写入以下参数:SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="需要修改名称的网卡MAC地址",ATTR{type}=="1" ,KERNEL=="eth*",NAME="eth0"参考配置:# vim 70-persistent-net.rulesSUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=="00:50:56:29:0e:ae",ATTR{type}=="1" ,KERNEL=="eth*",NAME="eth0"执行grub2-mkconfig -o /boot/grub2/grub.cfg命令生成更新grub配置参数
# grub2-mkconfig -o /boot/grub2/grub.cfgGenerating grub configuration file ...Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.imgFound linux image: /boot/vmlinuz-0-rescue-fe49b659ccb940fa8d260a5897c0b08aFound initrd image: /boot/initramfs-0-rescue-fe49b659ccb940fa8d260a5897c0b08a.imgdone重启Linux系统后验证网卡名称是否更改成功
# ifconfigeth0: flags=4163mtu 1500 inet 192.168.10.11netmask 255.255.255.0broadcast 192.168.10.255 inet6 fe80::250:56ff:fe29:eaeprefixlen 64scopeid 0x20 ether 00:50:56:29:0e:aetxqueuelen 1000(Ethernet) RX packets 86bytes 10889 (10.6 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 95bytes 10828 (10.5 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0lo: flags=73mtu 65536 inet 127.0.0.1netmask 255.0.0.0 inet6 ::1prefixlen 128scopeid 0x10 looptxqueuelen 1000(Local Loopback) RX packets 0bytes 0 (0.0 B) RX errors 0dropped 0overruns 0frame 0 TX packets 0bytes 0 (0.0 B) TX errors 0dropped 0 overruns 0carrier 0collisions 0总结
以上就是更改 RHEL7 或者 CentOS 7 的网卡名称的方法,最后看到 eth0 说明网卡名称更改成功!
666 看上去好乱~~~~~~~~~~~~
页:
[1]