I’ve been wondering why I can’t reference my guest OS by DNS name, as well as my host OS. At first I thought it was my DNS server, and there was one oddity there, but mostly it was an issue with the “default” virtual switch provided by Hyper-V. Eventually I learned through reading a dozen forum posts, that I needed to use a “public” virtual switch.
Reference Guest/Host by DNS name.
- Create a public virtual switch:
- Open the Hyper-V Manager
- Under Actions on the right, select “Virtual Switch Manager”
- You should only see one or two Switches:
- Default Switch - an internal switch which allows internet access but uses a private subnet for the VMs
- WSL (optional) - An internal switch which doesn’t allow internew access. Use by the Windows Subsystem for Linux 2 (WSL2)
- Select “New virutal network switch”
- Choose External for the type
- Click “Create Virtual Switch”
- Assign the VM to the public virtual switch:
- Select the VM
- Network Adapter
- Virtual switch: External
That’s it! You can now make network requests to the host and guest using their hostname.
Still Didn’t Work
If this didn’t work for you, then you’re going to need to ensure that your network has its own DNS server and that it is set as the primary DNS for your network.
Additionally, the DNS server itself should not be configured to forward local DNS queries. It must handle those itself.