Linux的虚拟机拷贝到另外的操作系统时,NAT方式的静态IP无效,一直是获取的DHCP动态地址

一、问题:

1、Linux虚拟机在A机的虚拟机中是NAT方式DHCP动态获取IP,设置了静态地址,IP地址不会发生变化,但是拷贝到B机上的虚拟机后,一直获取的时动态IP地址,无法得到静态IP。

2、执行/etc/init.d/network restart报错:

  1. [[email protected] init.d]# ./network restart
  2. 正在关闭接口 ens33: 错误 : [/etc/sysconfig/network-scripts/ifdown-eth] 设备 具有 MAC 地址 00:00:00:00:00:00
  3. 00:0C:29:94:8E:A2,而不是配置的地址 00:0C:29:8B:9A:F2。忽略。
  4. [失败]
  5. 正在关闭环回接口: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  6. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  7. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  8. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  9. [ 确定 ]
  10. 正在打开环回接口: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  11. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  12. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  13. Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  14. [ 确定 ]
  15. 正在打开接口 ens33: 错误:没有找到可用于连接 ‘ens33‘ 的设备。
  16. [失败]

3、执行 systemctl restart network报错:

  1. Job for network.service failed. See "systemctl status network.service" and "journalctl -xe" for details.

4、执行journalctl -xe报错:

  1. 5月 26 00:29:28 master /etc/sysconfig/network-scripts/ifdown-eth[1350]: 设备 具有 MAC 地址 00:00:00:00:00:00
  2. 00:0C:29:94:8E:A2,而不是配置的地址 00:0C:29:8B:9A:F2。忽略。
  3. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  4. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  5. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  6. 5月 26 00:29:28 master NetworkManager[709]: <info> (lo): link disconnected
  7. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  8. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  9. 5月 26 00:29:28 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  10. 5月 26 00:29:28 master NetworkManager[709]: <info> (lo): link connected
  11. 5月 26 00:29:29 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  12. 5月 26 00:29:29 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  13. 5月 26 00:30:39 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  14. 5月 26 00:30:40 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  15. 5月 26 00:30:40 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  16. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  17. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  18. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  19. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  20. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  21. 5月 26 00:30:41 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  22. 5月 26 00:30:42 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  23. 5月 26 00:30:42 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  24. 5月 26 00:30:42 master systemd[1]: Configuration file /usr/lib/systemd/system/tog-pegasus.service is marked world-inaccessible. This has no effect as configuration data is acce
  25. 5月 26 00:30:53 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  26. 5月 26 00:30:53 master network[1685]: 正在打开环回接口: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  27. 5月 26 00:30:53 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  28. 5月 26 00:30:53 master network[1685]: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  29. 5月 26 00:30:53 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  30. 5月 26 00:30:53 master network[1685]: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  31. 5月 26 00:30:53 master NetworkManager[709]: <info> parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
  32. 5月 26 00:30:53 master network[1685]: Could not load file ‘/etc/sysconfig/network-scripts/ifcfg-lo‘
  33. 5月 26 00:30:54 master network[1685]: [ 确定 ]
  34. 5月 26 00:30:54 master network[1685]: 正在打开接口 ens33: 错误:没有找到可用于连接 ‘ens33‘ 的设备。
  35. 5月 26 00:30:54 master network[1685]: [失败]
  36. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  37. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  38. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  39. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  40. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  41. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  42. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  43. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  44. 5月 26 00:30:54 master network[1685]: RTNETLINK answers: File exists
  45. 5月 26 00:30:54 master systemd[1]: network.service: control process exited, code=exited status=1
  46. 5月 26 00:30:54 master systemd[1]: Failed to start LSB: Bring up/down networking.
  47. -- Subject: Unit network.service has failed
  48. -- Defined-By: systemd
  49. -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  50. --
  51. -- Unit network.service has failed.
  52. --
  53. -- The result is failed.
  54. 5月 26 00:30:54 master systemd[1]: Unit network.service entered failed state.
  55. 5月 26 00:30:54 master systemd[1]: network.service failed.

二、解决:

Linux虚拟机从A拷贝到B后,MAC地址发生改变,但是配置文件中并没有同步修改,导致此问题。

1、首先执行ifconfig查看新的MAC地址:

  1. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  2. inet 192.168.130.109 netmask 255.255.255.0 broadcast 192.168.130.255
  3. inet6 fe80::20c:29ff:fe94:8ea2 prefixlen 64 scopeid 0x20<link>
  4. ether 00:0c:29:94:8e:a2 txqueuelen 1000 (Ethernet)
  5. RX packets 550 bytes 48524 (47.3 KiB)
  6. RX errors 0 dropped 0 overruns 0 frame 0
  7. TX packets 604 bytes 94343 (92.1 KiB)
  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  9. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  10. inet 127.0.0.1 netmask 255.0.0.0
  11. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  12. loop txqueuelen 0 (Local Loopback)
  13. RX packets 8 bytes 800 (800.0 B)
  14. RX errors 0 dropped 0 overruns 0 frame 0
  15. TX packets 8 bytes 800 (800.0 B)
  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

可以看出ens33网卡对应的MAC地址为:00:0c:29:94:8e:a2,即ether对应的地址。

2、修改ens33网卡对应的MAC地址

vi /etc/sysconfig/network-scripts/ifcfg-ens33

  1. TYPE="Ethernet"
  2. DEFROUTE="yes"
  3. IPV4_FAILURE_FATAL="no"
  4. NAME="ens33"
  5. UUID="707084bc-d3aa-483f-878b-c93e6abf4a07"
  6. ONBOOT="yes"
  7. HWADDR="00:0C:29:8B:9A:F2"
  8. BOOTPROTO="static"
  9. NM_CONTROLLED="yes"
  10. IPADDR="192.168.130.101"
  11. NETMASK="255.255.255.0"
  12. GATEWAY="192.168.130.2"

将HWADDR改为00:0c:29:94:8e:a2即可。

来自为知笔记(Wiz)

时间: 2024-10-25 20:39:45

Linux的虚拟机拷贝到另外的操作系统时,NAT方式的静态IP无效,一直是获取的DHCP动态地址的相关文章

Linux:Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21...

问题: Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21... 思路: 网上查找资料,得到解决方案如下: 编辑 /etc/sysconfig/network-scripts/ifup-eth, 将 (注:RHEL5.3 )if ! arping -q -c 2 -w 3 -D -I ${REALDEVICE} ${IPADDR} ; thenecho $”Err

VMware虚拟机中的CentOS,RHEL..Linux NET方式配置静态IP让虚拟机上外网

首先说下为什么使用NET的方式共享主机上的外网,由于笔记本经常携带,而公司或者家里的网络都是DHCP的方式,使用桥接就不是很方便, 每次都需要改下地址,不利于环境的配置,及后面的服务搭建... 1.第一步,我们需要配置VMware,给你需要上网的虚拟机设置为NET方式. 2.第二步将当前的网络共享给VMnet8这块虚拟网卡,并配置这块网卡. 找到宿主机上当前处于活动状态的网卡通过属性-->共享 3.第三步,需要设置vmwavre的虚拟网络编辑器配置,菜单编辑-->虚拟网络编辑器,设置设置子网.

vmware linux nat模式设置静态ip

网上资料很多,但是都不怎么实用,这里给大家总结一下.nat模式上网.因为nat本身就能上网为什么还要设置ip.这有点自找麻烦.但是在集群这是必须的.要么你搭建伪分布,要么至少具有三台物理机器.为了节省成本,一般会选择伪分布.伪分布也有选择,三种模式那种方式比较合适.1.桥接,这种方式对于大多数来说比较简单.只要设置一下ip,dns,网关等,主机和虚拟机之间关系不是很大.但是如果是pc机拨号上网,恐怕这种方式就不适合了.2.nat模式,可是自动获取ip,不需要设置即可实现上网,缺点不能和主机通信.

虚拟机NAT方式联网

使用nat方式设置静态ip时,本人的机子出现使用xxx.xxx.xxx.1时,一会能联网一会不能联网,并且有时候静态ip能联网,用DHCP方式不能联网,网关最好使用xxx.xxx.xxx.2,这时再使用静态ip就不会出现上述问题. 查找问题原因方法: 1.通过实践查看器找原因,发现有问题但是不是很清楚原因: 2.使用VM安装软件修复VM; 3.采用DHCP方式设置ip,发现能联网,查看网关(gateway)跟dns都是xxx.xxx.xxx.2: 4.修改虚拟机网络设置(在编辑下),修改成自己想

虚拟机Ubuntu16.04 Server设置NAT方式修改ip

每次都要查看ip,每次都不一样,往往我们会选择"NAT模式",但是选择的时候,ip地址会产生冲突,这样我们就要修改我们的IP地址来解决!! 一.简单方式: 1.工具栏'编辑' 2.虚拟网络编辑器,选择NAT模式==>子网ip没法修改 3.'更改设置' "子网IP"修改自己喜欢的网段,192.168.xxx.xxx最好是改这两个! 4.'DHCP设置' 修改起始IP地址==>可以说这样就是自己的虚拟机的IP地址 5.ifconfig看看!然后重启看看是不是

CentOS虚拟机NAT方式无法上网

一:CentOS虚拟机NAT方式无法上网 如下所示,网卡en016777736没有ip等信息:执行ping命令,报Network is unreachable的错误. 解决办法: 首先,打开运行,输入“services.msc”. 找到VMware NAT Service和VMware DHCP Service,先右击VMware DHCP Service,点击“停止”,然后开启“VMware NAT Service”,再开启“VMware DHCP Service”. 打开服务,在servic

虚拟机vmware,NAT静态IP配置和接入互联网

虽然网上有很多关于虚拟机vmware配置静态IP的文章,但是笔者还是要在这里写一下关于NAT下配置静态IP的心得,笔者可是在吃了大亏的情况下总结出来的. 首先正如大家都知道的首先要设置虚拟机的网络适配器的模式为NAT模式,如下图: 紧接着是这个过程中比较关键的部分了,那就是通过"编辑"-->"虚拟网络编辑器",查看NAT的虚拟网卡的配置信息,其中对于配置静态IP的部分特别重要的是要观察DHCP设置中的IP的区域,NAT静态IP的配置应该在该IP地址之间,一定要

linux更改静态ip

linux系统,严格按照下面步骤修改,既可以改成静态ip 如何在linux系统中设置静态ip地址 注意:文中的192.168.1.~应改成192.168.0.~,别照抄.第6步可以忽略.

linux kvm虚拟机使用

安装配置kvm 1.安装kvm软件包 [[email protected] ~]# yum install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v   2.安装kvm虚拟化管理工具包 [[email protected] ~]# yum install libguestfs-tools 3.查看虚拟化环境 (1)查看虚拟机环境   [[emai