Sharing VPN, Internet host networks with Hyper-V Ubuntu on Windows 10

Darr Mirr
5 min readFeb 14, 2022

Introduction

Windows 10 has WSL (Windows Subsystem for Linux) based on Ubuntu, but it does not provide full capability of standalone installation of Ubuntu. Therefore, I have to install Ubuntu in Hyper-V on my laptop.

It works fine in Hyper-V, but I faced with trouble:

I have no access to Internet and VPN networks from Ubuntu.

I have read a lot of articles about sharing host network with OS installed in Hyper-V. And no one really helps me.

In this guide I am going to show how to share all host network adapters with Ubuntu 20.04 launched in Hyper-V.

Guide steps:

  1. Create a virtual switch by using Hyper-V Manager.
  2. Plug internal VM switch into VM machine (Ubuntu).
  3. Share host Internet network.
  4. Configure connection settings in Ubuntu.
  5. Create Network address translation (NAT).

Point to note:

You must have admistrator access rights on host machine in order to complete this guide.

Create a virtual switch by using Hyper-V Manager

Internal VM switch wires host machine and virtual machine into local area network (LAN).

1. Search Open Hyper-V Manager and open it.
(If program is not found you have to enable it. Please see official guide.)

2. Select the Hyper-V host computer name on the left pane.

3. Select Action in menu and then choose Virtual Switch Manager in dropdown menu.

4. Choose internal type of virtual switch.

5. Click on Create Virtual Switch button.

6. Add a name for the virtual switch. For example, NATinternalVMSwitch.

7. Click “OK” button.

8. Click “Yes” button in “Apply network changes” pop-up window
(This pop-up window is not always arised. Therefore this step is optional.)

Please see official guide if you faced to issues with steps above.

Plug internal VM switch into VM machine (Ubuntu)

The next step is plug just created internal VM switch into VM machine.

1. Search Open Hyper-V Manager and open it.
(If program is not found you have to enable it. Please see official guide.)

2. Select the Virtual machine Ubuntu 20.04 at Virtual Machines pane.

3. Select Action in menu and then choose Settings… in dropdown menu.

4. Click on Add Hardware at the left pane in Settings for Ubuntu 20.04 pop-up window.

5. Select Network Adapter at the right pane.

6. Click “Add” button.

7. Choose created virtual switch (for example, NATinternalVMSwitch) in dropdown Virtual switch list.

8. Click on “Apply” button.

9. Click on “Ok” button.

Share host Internet network

The next step is share host Internet network. Why is need that? In such case Windows automatically makes all config job for you on the last step of this guide.

1. Search Control Panel and open it.

2. Choose Network and Internet.

3. Choose Network and Sharing Center.

4. Click on Change adapter settings.

5. Click right mouse button on your Internet adapter.

6. Choose Properties in dropdown menu.

7. Select Sharing tab in pop-up window.

8. Select “Allow other network users to connect through this computer’s Internet connection”.

9. Select internal VM switch. For example, NATinternalVMSwitch.

10. Unselect “Allow other network users to control or disable the shared Internet connection”

11. Click “Ok” button.

12. Click right mouse button on your internal VM switch. For example, NATinternalVMSwitch.

13. Choose Status.

14. Click on “Details…” button.

15. Remember or write down IPv4 Address and IPv4 Subnet Mask.

Configure connection settings in Ubuntu

Windows changes configuration internal VM network configuration after sharing. Therefore, we have to manualy set IP address, IP gateway in connection settings in Ubuntu.

1. Search Open Hyper-V Manager and open it.
(If program is not found you have to enable it. Please see official guide.)

2. Select the Virtual machine Ubuntu 20.04 at Virtual Machines pane.

3. Select Action in menu and then choose Start in dropdown menu.
(Skip this step if Ubuntu 20.04 has started yet.)

4. Select the Virtual machine Ubuntu 20.04 at Virtual Machines pane.

5. Select Action in menu and then choose Connect… in dropdown menu.

6. Login to Ubuntu.
(Usually, user credentials are set at OS installation stage.)

7. Click on icon with nine squares at the left corner.

8. Input “Settings” in search field.

9. Click on “Settings” icon.

10. Click on Network menu on the left pane.

11. Click on gear in the Wired section on the right pane.

12. Choose IPv4 tab in pop-up window.

13. Choose manual IPv4 method.

14. Write Gateway IP address.
(Gateway must be the same as IPv4 Address of NATinternalVMSwitch adapter on host machine)

15. Write Netmask.
(Netmask must be the same as IPv4 Subnet Mask of NATinternalVMSwitch adapter on host machine)

16. Write Address the same as Gateway and then change last octet on any digit in range between 2 and 255.
(For example, gateway: 192.168.130.1, address will be 192.168.130.131)

17. Turn off automatic DNS toggle.

18. Write Gateway IP address into DNS input field.

19. Click “Apply” button.

Open browser (Firefox) in Ubuntu and try to open any Internet site (for example, Yandex). Internet site is opened if you make all settings correctly.

Create Network address translation (NAT)

NAT helps to manage with task that I have to complete in this guide.

1. Search a PowerShell and open it as local admistrator.
(Hit right mouse button on PowerShell and choose “Run as administrator” in dropdown menu.)

2. Find the interface index of the virtual switch you have created early executing command:
Get-NetAdapter

3. Take note ifIndex for internal switch that you have created early. For example, NATinternalVMSwitch. It is going to use in the next step.

5. View internal switch adapter IP address and network mask in Windows network settings.

6. Configure the NAT gateway executing command (set your values for command parameters. Point to notice: IPAddress should be a new one. Thanks to Hassaan Muhammed for feedback):
New-NetIPAddress -IPAddress 192.168.130.1 -PrefixLength 24 -InterfaceIndex 9

7. Configure the NAT network using New-NetNat (set your values for command parameters):
New-NetNat -Name NATinternalVMSwitchNetwork -InternalIPInterfaceAddressPrefix 192.168.130.0/24

Please see official guide if you faced to issues with steps above.

Conclusion

Internet and VPN network resources should be accessable after applying this guide.

Sometimes host names could be incorrect resolved to its IP adresses. For example, you ping host sitename.yourvpn.ru, but ping request paththrough Internet adapter rather than VPN one. I found out 2 ways to solve this issue:

  • explicitly add mapping VPN IP address to host at file /etc/hosts on VM OS.
  • add VPN DNS to adapter DNS list on VM OS.

--

--