Set static IPs on Hyper-V VMs / Windows Servers - Best way?

Fred Marshall
Fred Marshall used Ask the Experts™
I set up a Windows Server testbed and asked a question here:
In the midst of the discussion, I tried to set a static IP address for each of the two VMs that I had implemented.
I used a method where I used Advanced Features of the VMs network adapter and assigned a MAC address.
Cliff Galiher took exception to what I did and I took that advice seriously.

Later, I tried to set things back to what I thought had been suggested but doing this broke the testbed.
So, the testbed remains with what I did....

I should point out that in the original testbed, each Server VM was on a different subnet and had a separate physical NIC.

Now I'm setting up another testbed with the real Servers and similar Hyper-V VMs.
I need to make sure that the VM Servers have static IP addresses - as before.
I don't want to overthink this or to overdo it.  
So, what is the recommended approach?
In this case, the 2 VMs in the Hyper-V platform will be in the same subnet and I envision one physical NIC for the pair.
So, in that sense, it's just a little simpler than the original testbed.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Architect - HA/Compute/Storage
From the host in an elevated PowerShell console:
$VMName = "DC01"
Enter-PSSession -VMName $VMName -Credential $VMName\Administrator

# Set variables
$IPAddress = ""
$Gateway = ""
$DNS0 = ""
$DNS1 = ""

# Set Static IP Address for the VM
Set-NetIPInterface -InterfaceAlias Ethernet -DHCP Disabled
Remove-NetIPAddress -InterfaceAlias Ethernet -Confirm:$false
New-NetIPAddress -InterfaceAlias Ethernet -IPAddress $IPAddress –DefaultGateway $Gateway -PrefixLength 24
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses $DNS0,$DNS1
IPConfig /RegisterDNS

Open in new window

That should do it.

I use VSCode for all of my PowerShell needs. This is a How-To get it all set up with a local Git repository.

PowerShell is simple, reliable, and repeatable thus consistent every time.


Philip Elder:  Thank you!  So, presumably one could do the same thing with the Windows GUI in the VM.
Either way, just as simple as that and what one really ought to expect!
Philip ElderTechnical Architect - HA/Compute/Storage

The advantage of using the PowerShell Remote Session is the time saved as one need not log on to the virtual machine until such time as software needs to be installed and configured.

Virtually all Microsoft Roles & Features can be installed, configured, and managed in this manner from a Hyper-V host.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

kevinhsiehNetwork Engineer

You can assign the IP address on the VM JUST LIKE A PHYSICAL MACHINE.

Don't over think this.


kevinhsieh:  yep.  I have no idea what I was thinking months ago when I set up the testbed.  ...  Probably best forgotten.


Thank you both!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial