centos7设置网卡名称为eth0

2023-02-24 17:07:47 浏览数 (1)

​ 安装好centos 7 之后默认网卡名称是很长一窜(比如:eno16777736),有时候需要刚才eth0这样的格式,下面是配置方法。

重命名ifcfg-eno16777736文件为ifcfg-eth0
代码语言:javascript复制
#cd /etc/sysconfig/network-scripts/
#mv ifcfg-eno16777736 ifcfg-eth0
更改ifcfg-eth0文件
代码语言:javascript复制
TYPE="Ethernet"
BOOTPROTO="dhcp"
DEFROUTE="yes"
NAME="eth0"			#<==此处改为eth0
DEVICE="eth0"
ONBOOT="yes"
编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”
代码语言:javascript复制
# vim /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root net.ifnames=0 biosdevname=0 rd.lvm.lv=centos/swap crashkernel=auto  <==net.ifnames=0 biosdevname=添加到这一行
rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数
代码语言:javascript复制
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-9f54c77324874c19be7420429678ad1e
Found initrd image: /boot/initramfs-0-rescue-9f54c77324874c19be7420429678ad1e.img
done
使用reboot命令重启操作系统,然后ifconfig查看网卡名称已经改成eth0了
代码语言:javascript复制
# reboot
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500   #可以看到已经改为eth0了
        inet 192.168.1.110  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe75:a9d1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:75:a9:d1  txqueuelen 1000  (Ethernet)
        RX packets 494  bytes 47088 (45.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 291  bytes 47105 (46.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

0 人点赞