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

Fred Marshall
Fred Marshall used Ask the Experts™
on
I set up a Windows Server testbed and asked a question here:
https://www.experts-exchange.com/questions/29143184/Hyper-V-VMs-physically-on-separate-subnets-howto.html
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.
Comment
Watch Question

Do more with

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

# Set variables
$IPAddress = "192.168.88.252"
$Gateway = "192.168.88.1"
$DNS0 = "192.168.88.254"
$DNS1 = "192.168.88.252"

# 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.

Author

Commented:
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!
Thanks
Philip ElderTechnical Architect - HA/Compute/Storage

Commented:
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

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

Don't over think this.

Author

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

Author

Commented:
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