温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在复制VM和VBOX虚拟机时重新配置网卡

发布时间:2020-06-03 21:48:30 来源:亿速云 阅读:522 作者:Leah 栏目:系统运维

如何在复制VM和VBOX虚拟机时重新配置网卡?这个问题可能是我们日常学习或工作经常见到的。通过这个问题,希望你能收获更多。今天跟随小编一起来看解决方案吧。

1、 新复制的虚拟机,请选择重新生成MAC地址,这个步骤在复制(克隆,WHATEVER)的时候,或者在复制完成,又或者完成后点配置,网卡属性,高级属性(各种平台各不相同,找到重新生成MAC地址,勾上或者刷新)。记录下这个MAC地址
2、新虚拟机启动以后,无论网络是否正常,停掉NetworkManager.Service...真的没有那么好用。
systemctl stop NetworkManager
systemctl disable NetworkManager
3、运行ifconfig -a, 得到新网卡的网卡名称,(也是设备名称,结合刚才记录下的MAC地址,很容易对上)
4、到/etc/sysconfig/network-scripts文件夹修改ifcfg-enxxx网卡启动配置文件
4.1、 强烈建议删除ifcfg-profile1类似这个脚本,这个是NetManager遗留。
4.2、 用uuidgen  enxxx这样的格式得到uuid写入配置档。
4.3、 写完配置档,重启网卡设备systemctl restart network。如果没有报错就完成了。

####举例:
###配置一个网卡最终要三个要素,设备名,MAC地址,UUID

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.201  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4a:b12c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 3647  bytes 3417904 (3.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 142  bytes 18249 (17.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.199.241  netmask 255.255.255.0  broadcast 192.168.199.255
        inet6 fe80::20c:29ff:fe4a:b136  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 5605  bytes 3465915 (3.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1400  bytes 322360 (314.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

###uuidgen (注意,UUID每次生成都不同,但是每个生成的ID都是可以用的)

[root@mysql01 dev]# uuidgen eno16777736
fd32246b-c655-45c6-ab6a-7a6aa84faa72
[root@mysql01 network-scripts]# uuidgen eno33554992
44e70d2f-4bf1-4753-865b-8fb042ecc8d6
设备名MAC地址UUID
eno1677773600:0c:29:4a:b1:2cfd32246b-c655-45c6-ab6a-7a6aa84faa72
eno3355499200:0c:29:4a:b1:3644e70d2f-4bf1-4753-865b-8fb042ecc8d6

###停止NetworkManager

[root@mysql01 network-scripts]# systemctl stop NetworkManager
[root@mysql01 network-scripts]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.

[root@mysql01 network-scripts]# systemctl status NetworkManager
* NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled)
   Active: inactive (dead) since 日 2020-01-26 14:22:15 CST; 36s ago
 Main PID: 8417 (code=exited, status=0/SUCCESS)

1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (eno16777736): Activation: successful, device activated.
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  wpa_supplicant running
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (virbr0): device state change: secondaries -> activated (reason 'none...100 0]
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (virbr0): Activation: successful, device activated.
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  caught SIGTERM, shutting down normally.
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  (virbr0): bridge port virbr0-nic was detached
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  (virbr0-nic): released from master virbr0
1月 26 14:22:15 mysql01 systemd[1]: Stopping Network Manager...
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  exiting (success)
1月 26 14:22:15 mysql01 systemd[1]: Stopped Network Manager.
Hint: Some lines were ellipsized, use -l to show in full.
[root@mysql01 network-scripts]# ifconfig

###写配置档:(这里的UUID可能和我上面获得的不同,因为配置档是之前就写好的.)
-rw-r--r--. 1 root root   292 1月  24 14:52 ifcfg-eno16777736
-rw-r--r--. 1 root root   367 1月  26 13:29 ifcfg-eno33554992

[root@mysql01 network-scripts]# cat ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=a808b074-580f-4ff7-b70a-e307769e8d96
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.1.201
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

[root@mysql01 network-scripts]# cat ifcfg-eno33554992
TYPE=Ethernet
BOOTPROTO=static
IPADDR0=192.168.199.241
PREFIXO0=24
GATEWAY=192.168.199.1
DNS1=192.168.199.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno33554992
UUID=9c7d8550-2d46-45c1-9c40-ef09570e1608
DEVICE=eno33554992
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

###重启网络服务:

[root@mysql01 network-scripts]# systemctl restart network.service
[root@mysql01 network-scripts]# 

###没有报错

[root@mysql01 network-scripts]# systemctl status network.service
* network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: active (exited) since 日 2020-01-26 14:27:22 CST; 18s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8612 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 8839 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

1月 26 14:27:17 mysql01 systemd[1]: Starting LSB: Bring up/down networking...
1月 26 14:27:17 mysql01 network[8839]: [29B blob data]
1月 26 14:27:19 mysql01 network[8839]: [37B blob data]
1月 26 14:27:22 mysql01 network[8839]: [37B blob data]
1月 26 14:27:22 mysql01 systemd[1]: Started LSB: Bring up/down networking.
[root@mysql01 network-scripts]# 

###尝试ifup/ifdown脚本:

[root@mysql01 network-scripts]# ifdown eno16777736
[root@mysql01 network-scripts]# ifconfig eno16777736
eno16777736: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 4359  bytes 4215191 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 169  bytes 22144 (21.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 network-scripts]# ifup eno16777736
[root@mysql01 network-scripts]# ifconfig eno16777736
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.201  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4a:b12c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 4362  bytes 4218484 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 187  bytes 25011 (24.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 network-scripts]# 
[root@mysql01 network-scripts]# ifdown eno33554992
[root@mysql01 Desktop]# ifconfig eno33554992
eno33554992: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 7980  bytes 4516864 (4.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2422  bytes 504771 (492.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 Desktop]# ifup eno33554992
[root@mysql01 Desktop]# ifconfig eno33554992
eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.199.241  netmask 255.255.255.0  broadcast 192.168.199.255
        inet6 fe80::20c:29ff:fe4a:b136  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 7982  bytes 4519567 (4.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2440  bytes 507648 (495.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 Desktop]# 

看完这篇文章,你们学会在复制VM和VBOX虚拟机时重新配置网卡了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI