完美解决linux网卡配置文件重启自动还原问题【如/etc/sysconfig/network

您所在的位置:网站首页 重启ip地址自动就变了 完美解决linux网卡配置文件重启自动还原问题【如/etc/sysconfig/network

完美解决linux网卡配置文件重启自动还原问题【如/etc/sysconfig/network

2023-09-06 01:51| 来源: 网络整理| 查看: 265

文章目录 说明解决方法方式一方式二

说明

虚拟机修改了/etc/sysconfig/network-scripts/ifcfg-eth0网卡文件 保存后,重启网络服务( systemctl restart network)是ip是存在并且能正常使用的。但是重启系统之后ifcfg-eth0内容被重置了。 你打开配置文件后,会发现,大概内容和下面一样,并且顶部都有一行注释,大概意思就是 有cloud-init自动创建,不要编辑这个文件。

# Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=dhcp DEVICE=eth0 HWADDR=fe:fc:fe:46:95:ba ONBOOT=yes TYPE=Ethernet USERCTL=no

而cloud-init是openstack的组件,所以这个问题一般发生在 openstack虚拟机或者配置了openstack的虚拟机上!!! (这种问题大概就是 openstack设置的ip段,这个虚拟机dhcp无法获取,所以ip就为空) 所以 cloud-init的配置文件这就不做解释,我的是普通虚拟机,但是我当初配置了openstack做实验,可能没卸载干净吧,有遗留问题发生了网卡重启被重置的问题。

解决方法 方式一

这是我在网上找的 步骤 我亲测不行,或许是因为我的openstack已经没有使用,组件不全导致的无效,如果你的openstack在正常使用,可以使用方式一。

尝试了关闭自带网络管理工具: [root@compute1 ~]# systemctl stop NetworkManager [root@compute1 ~]# systemctl disable NetworkManager

无效。重启后,ifcfg-eth0内容仍被重置。

找一找服务:systemctl list-unit-files | grep cloud* 是否有下面4项为enable [root@compute1 ~]# systemctl list-unit-files | grep cloud* cloud-config.service enabled cloud-final.service enabled cloud-init-local.service enabled cloud-init.service enabled cloud-config.target static 禁止 cloud-init服务接管网络

[root@compute1 ~]$vim /etc/cloud/cloud.cfg

#在最后面输入下列内容 network: config:disabled 清理,检查cloud-init配置文件 [root@compute1 network-scripts]$ cd /usr/lib/python2.7/site-packages/cloudinit/sources/ [root@compute1 network-scripts]$ rm -rf __init__.pyc [root@compute1 network-scripts]$ rm -rf __init__.pyo [root@compute1 network-scripts]$ rm -rf /var/lib/cloud/* [root@compute1 network-scripts]$ rm -rf /var/log/cloud-init* [root@compute1 network-scripts]$ cloud-init init --local [root@compute1 network-scripts]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 [root@compute1 network-scripts]$ reboot 方式二

我这个方式比较暴力,因为我不用openstack了,而我这个问题是cloud.init引起的问题,所以我就把和cloud.init的所有服务都停了并关闭开机自启!

[root@compute1 network-scripts]$systemctl disable cloud-init-local cloud-init cloud-config cloud-final [root@compute1 network-scripts]$systemctl stop cloud-init-local cloud-init cloud-config cloud-final [root@compute1 ~]# [root@compute1 ~]# systemctl list-unit-files | grep cloud* cloud-config.service disabled cloud-final.service disabled cloud-init-local.service disabled cloud-init.service disabled cloud-config.target static

配置网络,重启服务器,ip依旧存在,问题解决!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3