moving a centos virtual machine in hyper-v and fixing network issues afterwards

i have been testing an NGINX cache i have setup for caching steam games and i have been testing download speeds having the cache on different types of disks so i could find what has the best performance, but every time ive moved it my network config gets messed up in centos 7.  ive had to figure out how to fix it 3 times now because i forgot how i did it, now i dont have the normal network configuration i have the network configuration tool disabled and manually set the nic settings in /etc/sysconfig/network-scripts/. when you delete the virtual machine and re-create it on another disk using the old disk image the new vm will generate a new MAC address for said machine which throws the manual config off because its looking for another networking device. heres the steps to fix this.

First open /etc/sysconfig/network-scripts/ in your favorite editor and look at the mac address. this will be usually in a vm “ifcfg-eth0” or whatever your adapter name is. simply open that file and look under “HWADDR=xx:xx:xx:xx:xx:xx:xx” that is the mac address your machine is going to be looking for to reconnect the nic.

now that we have the hardware address (MAC address) that we are looking for lets go into hyper-v settings for that VM and look at the options we have. first shut down the virtual machine, then right click the VM in hyper-v manager and click “settings” in the left panel click the  “+” sign next to “network adapter” go down to “advanced features” and in the right column you will see the “advanced features” options where it says “MAC address” change it from dynamic to static and check the box next to “enable MAC address spoofing”
then type the HWADDR under static.

Once you get that typed in there go ahead and click apply then power the virtual machine back up, it should fix the network configuration settings and it should boot normally with a working network config. To verify the network config is working correctly type in

sudo systemctl status network.service

if it succeeds and all is green you are ready to go, if not you might have something else wrong.

thanks for reading!