centos7系统安装后,网卡名的命名不方便记忆,需要更改(像这种enp0s31f6)
首先更改/etc/sysconfig/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
为
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
执行 grub2-mkconfig -o /boot/grub2/grub.cfg //更新GRUB、内核配置
grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1b40983623514e3aa17fc6145d13d929
Found initrd image: /boot/initramfs-0-rescue-1b40983623514e3aa17fc6145d13d929.img
done
获取网卡enp0s31f6的mac地址并添加设备规则配置文件
ip link show enp0s31f6 | grep ether | awk '{print $2}'
多网卡更改可以一并导入到/etc/udev/rules.d/70-persistent-net.rules
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"74:86:e2:25:fd:a7\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"eth1\"" >> /etc/udev/rules.d/70-persistent-net.rules
重新生成网卡文件
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOF
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.97.2
NETMASK=255.255.255.0
EOF
重启机器即可