测试平台
VMWARE WORKSTATION 15
虚拟机系统Centos7
centos7网卡的随机名给自动化运维带来混乱,那么我们把网卡名重新配置为ethX
一、在安装系统的时候配置:
修改内核选项:net.ifnames=0 biosdevname=0
![1992c1f6a953fedafe21ee59de6bab54.png](https://i-blog.csdnimg.cn/blog_migrate/1f75a7a9169f4edfbc827eaa19bdb58a.jpeg)
二、已安装系统修改方法
![f604293d009a1e403927a379bd27853b.png](https://i-blog.csdnimg.cn/blog_migrate/421da804311406e15f21e68dc6006929.jpeg)
像我的虚拟机,网卡名称是ens32。
1、编辑网卡信息
cd /etc/sysconfig/network-scripts/ #进入网卡目录
mv ifcfg-ens32 ifcfg-eth0 #重命名网卡
sed -i 's/ens32/eth0/g' ifcfg-eth0
#cat ifcfg-eth0
2、修改grub
(有些文章说修改/etc/sysconfig/grub,但我试过有问题。)
修改前:
#cat /etc/default/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"
替换 “rhgb quiet” 为 “rhgb net.ifnames=0 biosdevname=0 quiet”
sed -i 's@rhgb quiet@rhgb net.ifnames=0 biosdevname=0 quiet@g' /etc/default/grub
查看修改后的配置:
#cat /etc/default/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 net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
生成新的启动菜单:
# grub2-mkconfig -o /boot/grub2/grub.cfg #生成启动菜单
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-e1430ad5bd3b4ba3817d626dd289064e
Found initrd image: /boot/initramfs-0-rescue-e1430ad5bd3b4ba3817d626dd289064e.img
done
查看生成的/boot/grub2/grub.cfg
3、验证是否修改成功
reboot #重启系统生效
yum install net-tools #默认centos7不支持ifconfig 需要安装net-tools包
#检查网卡信息
ifconfig eth0
来事了,可能看到网卡没有得到ip。
![90ee8d2fd081c1153c5de68e63affad9.png](https://i-blog.csdnimg.cn/blog_migrate/1f70b9f145f841e920845afb3710344d.jpeg)
# nmcli connection show
# nmcli connection delete "Wired connection 1"
Connection 'Wired connection 1' (cb2e62d9-5870-329b-9f78-9ecb6245e444) successfully deleted.
# 添加一个网卡连接
# nmcli connection add type ethernet con-name eth0 ifname eth0
---------------------
版权声明:本文为CSDN博主「运维自动化&云计算」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://yunwei365.blog.csdn.net/article/details/90679106