# Linux—Centos7 修改网卡名称
首先我们先了解不同网卡名称对应的内核参数:
- biosdevname=0 net.ifnames=1:网卡名 “enps” 此内核参数一般为默认
- biosdevname=1 net.ifnames=0:网卡名 “em*”
- biosdevname=0 net.ifnames=0:网卡名 “eth*”
本次以将网卡名命名为 eth * 格式作示例
# 1. 查看当前网卡的信息
[root@manager ~]# ifconfig | |
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 | |
inet 192.168.40.88 netmask 255.255.255.0 broadcast 192.168.40.255 | |
inet6 fe80::b92f:3dd3:19e7:1311 prefixlen 64 scopeid 0x20<link> | |
ether 00:0c:29:5e:a0:59 txqueuelen 1000 (Ethernet) | |
RX packets 75 bytes 8065 (7.8 KiB) | |
RX errors 0 dropped 0 overruns 0 frame 0 | |
TX packets 63 bytes 7754 (7.5 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 1000 (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 |
# 2 . 修改配置文件
(1)在下列路径下找到 ifcgf-ens33
[root@manager ~]# cd /etc/sysconfig/network-scripts/ | |
[root@manager network-scripts]# ls | |
ifcfg-ens33 ifdown-ippp ifdown-routes ifup ifup-ipv6 ifup-ppp ifup-tunnel | |
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wireless | |
ifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-global | |
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functions | |
ifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6 |
(2)使用 MV 命令,修改当前网卡的名称
[root@manager ~]# mv ifcfg-ens33 ifcfg-eth0 | |
[root@manager network-scripts]# ls | |
ifcfg-eth0 ifdown-ippp ifdown-routes ifup ifup-ipv6 ifup-ppp ifup-tunnel | |
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wireless | |
ifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-global | |
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functions | |
ifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6 |
(3)同步修改网卡配置文件中的 name 和 device,修改为需要配置网卡的名字
NAME="ens33" | |
DEVICE="ens33" | |
将上列命令修改为 | |
NAME="eth0" | |
DEVICE="eth0" |
(4)修改 grub
[root@manager ~]# cd /etc/default/ | |
#编辑内核信息,在 GRUB_CMDLINE_LINUX 行添加字段 net.ifnames=0 biosdevname=0 | |
[root@manager default]# cat 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" | |
GRUB_DISABLE_RECOVERY="true" | |
#生成启动菜单 | |
[root@manager default]# grub2-mkconfig -o /boot/grub2/grub.cfg |
(5)完成之后 reboot 重启系统即可
[root@manager default]# reboot |
(6)使用 ifconfig 即可查看
[root@manager ~]# ifconfig | |
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 | |
inet 192.168.40.88 netmask 255.255.255.0 broadcast 192.168.40.255 | |
inet6 fe80::63d4:467f:9b76:e34f prefixlen 64 scopeid 0x20<link> | |
inet6 fe80::1856:7b0:9d1e:7208 prefixlen 64 scopeid 0x20<link> | |
ether 00:0c:29:5e:a0:59 txqueuelen 1000 (Ethernet) | |
RX packets 77 bytes 8117 (7.9 KiB) | |
RX errors 0 dropped 0 overruns 0 frame 0 | |
TX packets 62 bytes 7842 (7.6 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 1000 (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 |