The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.
Create the Switch
In Hyper-V Manager, create a new Virtual Switch, under
Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the
External switch type.
On the next screen, give the switch a name, such as
internet-enabled, and choose the physical network interface that is connected to the Internet.
The resultant switch should look something like this:
Hard-Code the Switch's IP Address (Gateway for the VM)
Locate the network adapter that is associated with the new switch, i.e., under
Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g.,
vEthernet (internet-enabled). Right-click the adapter and choose
Internet Protocol Version 4 (TCP/IPv4) and click
192.168.10.1 for the
IP address, and
255.255.255.0 for the
Subnet mask. The settings should look like this:
Assign a Static IP Address in Guest VM
The final step is to assign a static IP address in the guest VM.
Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.
Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.
The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing
/etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):
After saving the file, apply the changes with:
$ sudo netplan apply
The VM should reflect the static IP immediately, which can be confirmed with
$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
The host can now ping the guest at
192.168.10.10, and the guest can ping the host at