虚拟机更改网卡名称
VMWare装的CentOS虚拟机的自带网卡名有点乱,想重新定义一下。
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
并且是最小化安装。
这里启动下网卡,获得IP,好连接shell
systemctl restart networkip addr
默认使用DHCP,都是自动获取的IP
CentOS7使用了“一致性网络命名方法”,这里举例,将网卡名截断为前5个字符,如eno16777736改为eno16。
复制ETH1和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
修改/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查看)
reboot