弹性云服务器 ECS-如何解决多网卡的Linux弹性云服务器变更规格后网卡漂移?:处理方法
处理方法
- 远程登录出现网卡漂移的云服务器。
- 执行以下命令,修改“/boot/grub2/gurb.cfg”文件。
在“/boot/grub2/gurb.cfg”文件中,增加biosdevname=0, net.ifnames=0,如果文件中已经有该配置项,则跳过本步骤,不用添加。
cat /boot/grub2/grub.cfg I grep linux I grep net.ifnames
1inux /boot/vmlinuz-5.10.0-60.18.0.50.r865_35.hce2.x86_64 root=UUID=bb9f8e28-4582-48d5-9fe8-d76d32466d03 ro biosdevname=0 net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 nohz=off mitigations=off crashkernel=512M crash_kexec_post notifiers panic=3 nmi_watchdog=1 selinux=0 rd.shel1=0 1inux /boot/vmlinuz-0-rescue root=UUID=bb9f8e28-4582-48d5-9fe8-d76d32466d03 ro biosdevname=0 net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0, 115200n8 nohz=off mitigations=off crashkernel=512M crash_kexec_post_notifiers panic=3 nmi_watchdog=1 selinux=0 rd.shel1=0
- 执行以下命令,添加udev规则,在“/etc/udev/rules.d/”下创建一个MAC地址和网卡名称的映射规则,并给予可执行权限。
cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:79:5f:a1", ATTR{type}=="1", KERNEL=="eth*", NAME="net_eth0" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:79:5c:1b", ATTR{type}=="1", KERNEL=="eth*", NAME="net_eth1" SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:79:58:78", ATTR{type}=="1", KERNEL=="eth*", NAME="net_eth2"
- 执行以下命令,给予映射规则可执行权限。
- 执行以下命令,修改“/etc/sysconfig/network-scripts/ifcfg-$name”下网卡配置文件名和文件中“DEVICE=$name”字段对应值的名字一一对应。
- 执行以下命令,重新生成grub配置并更新内核参数。
不同操作系统的grub代次有差异,例如update-initramfs和mkinitrd。
grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ... Found linux image: /boot/vmlinuz-5.10.0-60.18.0.50.r865_35.hce2.x86_64 Found initrd image: /boot/initramfs-5.10.0-60.18.0.50.r865_35.hce2.x66_64.img Found linux image: /boot/vmlinuz-0-rescue Found initrd image: /boot/initramfs-0-rescue.img Adding boot menu entry for UEFI Firmware Settings ... done
- 执行以下命令,重启云服务器即可使配置生效。
reboot
- 执行以下命令,查看网卡设备名称与网卡MAC地址的映射关系。