Resetting the Network Stack in a Linux Virtual Machine

When you change network settings in an instant clone, you must reset the network stack of the virtual NIC to adopt the new settings. For a Linux guest operating system, you must unbind and rebind the network driver so it adopts a new MAC address.

The following shell script rebinds all network drivers:

#!/bin/bash
for NETDEV in /sys/class/net/*
do
  DEV_LABEL=`basename \`readlink -f $NETDEV/device\``
  DEV_DRIVR=`basename \`readlink -f $NETDEV/device/driver\``
  echo $DEV_LABEL > /sys/bus/pci/drivers/$DEV_DRIVR/unbind
  echo $DEV_LABEL > /sys/bus/pci/drivers/$DEV_DRIVR/bind
done

If the guest operating system was configured to use DHCP, you must also force a DHCP refresh after the MAC addresses refresh has completed.

Tip: Avoid resetting the network stack in the guest operating system while you are working over a network connection, such as SSH. You can run the shell commands to reset the stack as part of a customization script installed in the guest operating system of the source virtual machine before running the instant clone operation.