虚拟机更改网卡名称

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/eagle89/article/details/82180343

虚拟机更改网卡名称

VMWare装的CentOS虚拟机的自带网卡名有点乱,想重新定义一下。

环境

1、VMWare虚拟机

2、系统

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

并且是最小化安装。

网卡信息

网卡配置文件

配置内容

 

这里启动下网卡,获得IP,好连接shell

systemctl restart network
ip addr

默认使用DHCP,都是自动获取的IP

配置

CentOS7使用了“一致性网络命名方法”,这里举例,将网卡名截断为前5个字符,如eno16777736改为eno16。

1、更改网卡配置文件名

复制ETH1和2,并把设备名改了
 

2、关闭“一致性网络设备命名法”

 cat /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=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@localhost ~]# 

添加net.ifnames=0 biosdevname=0后

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

更新GRUB、内核配置

 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-f034e6e19df748b7a27fad77b06e3179
Found initrd image: /boot/initramfs-0-rescue-f034e6e19df748b7a27fad77b06e3179.img
done

3、添加设备规则配置文件

修改/etc/udev/rules.d/70-persistent-net.rules,没有该文件则新建文件

内容如下

cat /etc/udev/rules.d/70-persistent-net.rules

# ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="eth0"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="eth1"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="eth2"

注意MAC地址与NAME相匹配(可以用ip addr查看)

4、重启

reboot

猜你喜欢

转载自blog.csdn.net/eagle89/article/details/82180343