欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos7.x 更改网卡名称eth0

程序员文章站 2022-06-03 17:59:10
...
1、修改网卡信息
cd /etc/sysconfig/network-scripts/
重命名网卡名称
mv ifcfg-eno16777728 ifcfg-eth0
编辑网卡信息
vim ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0 #name修改为eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.16.8.254
PREFIX=24
GATEWAY=172.16.8.1
DNS1=114.114.114.114

2、修改grub文件

编辑内核信息,添加net.ifnames=0 biosdevname=0字段的
vim /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 rd.lvm.lv=devops/root rd.lvm.lv=devops/swap rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"

运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数                             
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-cd4cedc54acd4c289771cd4af02255e8
Found initrd image: /boot/initramfs-0-rescue-cd4cedc54acd4c289771cd4af02255e8.img
done

3、重启系统及验证

必须重启系统生效
reboot  

[[email protected] ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.8.254  netmask 255.255.255.0  broadcast 172.16.8.255
        inet6 fe80::20c:29ff:fe30:707a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:30:70:7a  txqueuelen 1000  (Ethernet)
        RX packets 105  bytes 13994 (13.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 112  bytes 14592 (14.2 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 0  (Local Loopback)
        RX packets 4  bytes 340 (340.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 340 (340.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0