CentOS 7修改网卡名称

时间:2021-11-29 19:32:02

CentOS 7 修改网卡名为eth0

标签: linux


笔者Q:972581034 交流群:605799367。有任何疑问可与笔者或加群交流

CentOS7的网卡名称太长,这不符合我们的使用习惯,增加了管理难度,最简单粗暴的方法是在安装系统的时候就把网卡名改了。当然,安装好的系统也是可以修改的。下面分别介绍两种方法。

方法一:

在进入安装界面的时候把光标移动到Install CentOS7,按下tab键,在后面输入“ifnames=0 biosdevname=0”回车即可。

CentOS 7修改网卡名称

方法二:

进入网卡配置文件目录

[root@centos7 ~]# cd /etc/sysconfig/network-scripts/

重命名网卡

[root@centos7 network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0

修改配置文件NAME、DEVICE

[root@centos7 network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=552c01f7-fd9d-4f19-913e-379a2bf5a467
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.111
"ifcfg-eth0" 14L, 239C written

修改grub

sed -i.bak 's#crashkernel=auto rhgb quiet#crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet#g' /etc/sysconfig/grub
[root@centos7 network-scripts]# 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 rhgb net.ifnames=0 biosdevname=0 quiet"
"/etc/sysconfig/grub" 7L, 263C written

生成启动菜单

[root@centos7 network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
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-7ed5d4eebe4c43e3aadbda68cd0ef311
Found initrd image: /boot/initramfs-0-rescue-7ed5d4eebe4c43e3aadbda68cd0ef311.img
done

重启系统生效

[root@centos7 network-scripts]# reboot

查看是否成功

centos7默认没有ifconfig命令,需yum install net-tools -y安装

[root@centos7 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.111 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe57:875c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:57:87:5c txqueuelen 1000 (Ethernet)
RX packets 39 bytes 4887 (4.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 43 bytes 7502 (7.3 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 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