Cloned Virtualbox VM Network Issues


I spent hours trying to figure out why my cloned VM was not saving its ifconfig changes. Even though you can tell Virtualbox to regenerate the network ID when cloning, you still won’t have a working VM if you create a new one later using the cloned image. It turns out that you must delete the persistent network rule and apply a new MAC address. Thanks, Oracle, for making this completely clear utterly baffling.

1. Generate a new MAC in Virtualbox and notate it.

Generate a new MAC address for the VM

2. Run the following to delete all persistent net rules:

rm -f /etc/udev/rules.d/70*net*

3. Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file and replace the MAC address with the one you generated above, then save:

vi /etc/sysconfig/network-scripts/ifcfg-eth0
Replace the MAC address in /etc/sysconfig/network-scripts/ifcfg-eth0

Replace the MAC address in /etc/sysconfig/network-scripts/ifcfg-eth0

4. Run sys-unconfig. This command will reset system settings and force a shutdown. When you reboot you will be presented with root password reset, network configuration and services autostart setup screens.

You should now be able to configure eth0 with a new IP address which will not be overwritten and lost. It seems that iptables is unaffected, so that’s good.

 

Reset SSHD (SSH) config

In CentOS, the SSHD service will not work from a cloned VM, either. This is because the /etc/ssh/sshd_config file is still configured with the old IP address. Edit this file and save it, then restart the SSHD service (service sshd restart).

Change the ListenAddress in the /etc/ssh/sshd_config file

Change the ListenAddress in the /etc/ssh/sshd_config file