linux修改网卡名为eth0
安装完系统后进行修改。
第一步:系统安装结束后查看当前网卡名称为ens33.
[root@pazzn ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.131 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::1dc3:7a21:103e:c958 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d5:85:54 txqueuelen 1000 (Ethernet) RX packets 117 bytes 14086 (13.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 109 bytes 15871 (15.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
第二步:编辑网卡的配置文件
将”/etc/sysconfig/network-scripts/ifcfg-ens33“的NAME与DEVICE参数项修改为eth0。将网卡配置文件ifcfg-ens33修改为ifcfg-eth0
[root@pazzn ~]# cd /etc/sysconfig/network-scripts/ [root@pazzn network-scripts]# vi ifcfg-ens33 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="dhcp" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME=" eth0" UUID="c3136d13-6e1e-4a7b-bcfb-f8e85e0351e0" DEVICE="eth0" ONBOOT="yes" [root@pazzn network-scripts]#mv ifcfg-ens33 ifcfg-eth0
第三步:修改grub来禁用该命名规则
编辑grub配置文件/etc/sysconfig/grub,在GRUB_CMDLINE_LINUX变量中添加一句”net.ifnames=0 biosdevname=0“.
[root@pazzn grub2]#vi /etc/sysconfig/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet" GRUB_DISABLE_RECOVERY="true" [root@pazzn grub2]# cat /etc/default/grub ###这个目录的和sysconfig的一样的,编辑sysconfig那里添加进去之后默认这里就会添加上了 GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0 biosdevname=0" GRUB_DISABLE_RECOVERY="true
第四步:重新生成grub配置并更新内核参数
运行命令:grub2-mkconfig -o /boot/grub2/grub.cfg
[root@pazzn grub2]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-77419a0d119c43968d735f6a0b8534f4 Found initrd image: /boot/initramfs-0-rescue-77419a0d119c43968d735f6a0b8534f4.img done
[root@pazzn grub2]#
第7步:重启系统后验证
[root@pazzn ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.131 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::bf21:39fc:b077:3c9b prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d5:85:54 txqueuelen 1000 (Ethernet) RX packets 801 bytes 84912 (82.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 520 bytes 83725 (81.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@pazzn ~]#
专业从事搬砖多年,还是在继续搬砖中,厚积薄发~