How to setup HyperV virtual machine to have static IP and have access to internet?

5

3

Is possible to setup HyperV virtual machine to have static IP and also have access to internet ? (on latest Windows 10 Pro)

To sum up, requirements are like so:

  • virtual machine should have local (manually defined) IP like 192.168.1.18 (ideally defined from host computer, not in VM)
  • virtual machine should be ideally accessible only from host computer (not from public)
  • virtual machine should have access to internet (from wifi adapter where must be defined DHCP)
  • would be great if Virtual Machine (guest) could stay in DHCP client mode

Machine is created by Vagrant but probably will need manual tweaking - as Vagrant static IP bug is open here.

PS. I am web developer with basic understanding of networking, so please keep that in mind with possible explanations :)

Jurosh

Posted 2018-02-16T15:22:51.813

Reputation: 189

1Yes. This is a very common configuration. Have you tried to set this up and are facing some specific problem? – I say Reinstate Monica – 2018-02-16T15:27:01.963

Yea I've tried some things but ended neither not able to connect to VM, or not working network at all... :/ so I hoped someone was dealing with similar issue and can provide "dummy style" help. Will try again, and can post details later if no luck... – Jurosh – 2018-02-16T16:16:47.603

Answers

2

Yes, this is possible. You'll use the guest operating system's network configuration utility to set the static IP address. Make sure to include a default gateway and DNS Servers so you can browse the internet.

After that, it's just a matter of setting the firewall to only allow connections from the host machine and blocking all other inbound connections.

Allen Howard

Posted 2018-02-16T15:22:51.813

Reputation: 565

1I was thinking that there is solution without modification of VirtualMachine (guest) - something what will say that virtual machine should be assigned this IP so guest can stay as DHCP client.. Which network interface switch should I use in your example ? – Jurosh – 2018-02-16T16:37:02.340

You'll want an external switch. You can use a MAC address reservation within DHCP if you have access to the DHCP server. You'll have to set a static MAC address and not just he dynamic one generated by HyperV. – Allen Howard – 2018-02-16T16:38:20.447

But there might be one issue, if I type gateway and IP inside machine, will this solution work on all networks ? -- I am connected through WiFi adapter so my network is based on DHCP on place I work.. so host PC can have different IPs (& subnets) as one defined in guest machine... – Jurosh – 2018-02-16T16:48:56.150

If you connect to different networks, then a MAC address reservation won't help. If you statically set a network address in the VM, it won't have access to anything on a different network. Your host NIC would still be using DHCP, and thus would get an IP address properly. – Allen Howard – 2018-02-16T16:55:41.690