Centos7.2 修改网卡名称

时间:2021-08-22 21:28:32

查看ip

[root@localhost network-scripts]# ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::a7:a0:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.105/ brd 192.168.1.255 scope global dynamic eno16777736
valid_lft 4214sec preferred_lft 4214sec
inet 192.168.1.122/ brd 192.168.1.255 scope global secondary eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::ac30:2bcb:e910:3ae/ scope link
valid_lft forever preferred_lft forever
: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc noqueue state DOWN qlen
link/ether ::::cb:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/ brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
: virbr0-nic: <BROADCAST,MULTICAST> mtu qdisc pfifo_fast master virbr0 state DOWN qlen
link/ether ::::cb:1a brd ff:ff:ff:ff:ff:ff
[root@localhost network-scripts]# ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::a7:a0:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.105/ brd 192.168.1.255 scope global dynamic eno16777736
valid_lft 4157sec preferred_lft 4157sec
inet 192.168.1.122/ brd 192.168.1.255 scope global secondary eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::ac30:2bcb:e910:3ae/ scope link
valid_lft forever preferred_lft forever
: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc noqueue state DOWN qlen
link/ether ::::cb:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/ brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
: virbr0-nic: <BROADCAST,MULTICAST> mtu qdisc pfifo_fast master virbr0 state DOWN qlen
link/ether ::::cb:1a brd ff:ff:ff:ff:ff:ff

可以发现网卡名称eno16777736,现在想要修改名称

/etc/sysconfig/network-scripts/ifcfg-eno16777736 

打开文件,修改内部的DECIVE为eth0,保存退出

重命名,将文件ifcfg-eno16777736文件名修改为eth0

cd /etc/sysconfig/network-scripts/
mv ifcfg-eno16777736 ifcfg-eth0

禁用该可预测命名规则。对于这一点,你可以在启动时传递“net.ifnames=0 biosdevname=0 ”的内核参数。这是通过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX变量来实现的。

gedit  /etc/sysconfig/grub

原内容:

GRUB_TIMEOUT=
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=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

修改后:

GRUB_TIMEOUT=
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=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"

构建新的img文件

[root@localhost sysconfig]#  grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.-514.10..el7.x86_64
Found initrd image: /boot/initramfs-3.10.-514.10..el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.-.el7.x86_64
Found initrd image: /boot/initramfs-3.10.-.el7.x86_64.img
Found linux image: /boot/vmlinuz--rescue-ca3d9f9f71fb441da7b400bf4c01ce84
Found initrd image: /boot/initramfs--rescue-ca3d9f9f71fb441da7b400bf4c01ce84.img
done

重新启动服务器

[root@localhost ~]# reboot

重新查看ip地址:

不要打我,我这边报Mac地址冲突,但是网上很多人这么操作是成功的,后面再尝试!

http://www.jb51.net/article/120340.htm

http://www.linuxidc.com/Linux/2017-03/141384.htm