Networking Hyper-V & Linux / Ubuntu virtual machine internet access
You’re probably here because you want a quick and simple way of giving your Hyper-V virtual machine internet access. Look no further, it’ll take you less time than to boil the kettle for a cup of tea.
It’s worth noting this guide is not intended for production environments. You should refer to the Microsoft documentation for setting up secure Virtual Machines.
If you have already tinkered with your Hyper-V’s Virtual Switch Manager and somehow broken general network connectivity or you’re getting an annoying “Network adapter doesn’t exist”, “You have broken me, go away”, this guide won’t help you.
I suggest you totally uninstall Hyper-V and reinstall it to solve any issues first. Don’t worry though, your existing Virtual Machines will remain BUT do take a backup before doing so!
The getting started checklist:
- Internet works on the system that has Hyper-V installed.
- There aren’t any weird Firewalls rules or Virus scanners on Windows causing havoc.
Your virtual machine needs access to your host computer’s internet connection. This is quite simple enough to do.
We need to:
- Create an External Switch on the Hyper-V
- Make our Virtual Machine use the External Switch for it’s Network Adapter,
- Share your host machines Network Adapter with your External Switch:
Step 1 – Hyper-V External Switch
Create a new External Virtual Switch:
Fill out the details.
Name: Set a name to whatever you like
Connection Type: Select External network
External Network: Select your host computers Network adapter that has an internet connection.
Great – we have step 1 wrapped up.
Step 2 – VM network adapter
This is a simple step – open the settings for your Virtual Machine.
Select your Virtual Machine from the list in Hyper-V, right click and select Settings:
In the settings window for your Virtual Machine
- Select Network Adapter from the left menu
- On the right side, click on the Virtual Switch drop down select your External Switch.
- Hit OK to save.
Step 3 – Host computer internet sharing
This is probably the most important step. The idea is to open the doorway of your host computers internet with the Hyper-V setup.
Technically it’s not bridging, but let’s just loosely use the term bridge. There two islands that need to be connected:
Open Windows Network Connections.
Hit start, search for ncpa.cpl and hit enter (Windows 10). You can also go to the Windows Control Panel too.
Find your main network adapter from the list which has internet. Right click and select Properties.
This will open the Properties window.
Now do the following:
- Click the Sharing tab
- Tick the highlighted box and select the Hyper-V External Network Switch you created earlier.
- Click OK to save
At this point Windows will reconfigure the network settings for this to take effect.
When this has finished – make sure your host pc’s Windows still works. I.e. Open your favourite browser and check if you can still access websites.
Step 4 – Testing the VM for internet
For this step, simply restart the VM for the network settings to take affect (or restart the networking service, whatever you feel comfortable with).
When your VM comes back up, it should now have internet access. You can check by opening a linux terminal, running the ifconfig to check it’s IP address.
You can also ping a website to check. Alternatively if you’re using a Desktop interface, just fire up a browser and check if you have internet.