Monday, April 27, 2015

Installing Ubuntu 14.04.2 LTS (Desktop x64) on Hyper-V and Configure it to Connect to Internet

I had a really hard time installing Ubuntu 14.04.2 LTS (Desktop x64) on Hyper-V and configuring it to connect to Internet. Of course the installation was smooth, but configuring the Ubuntu to have Internet was a disaster for me. Have read many articles, tried different scenarios and got myself into a mess  with multiple virtual Internal and External switches. Started to hate Hyper-V, but apparently, things went well.

And this is a step by step guide for you to start from scratch. Please not that, I am not going to go in detail about creating a virtual machine on Hyper-V.

I will be explaining the process with External and Internal virtual switches.

External Virtual Switch

My environment is Windows 8.1 with a working Wi-Fi connection. No previously created Internal or External virtual switches.

The version of Ubuntu I am going to install on Hyper-V is, Ubuntu 14.04.2 LTS (Desktop x64).

In New Virtual Machine wizard, in Configure Networking, I am selecting Not Connected.

9
New Virtual Machine Wizard
2
Installation Summary
Now do the installation, in the middle of installation, you can see that you don’t have internet. That’s of course obvious.

5
Not connected to Internet
Once installed, for worse case, shut down the newly created Ubuntu virtual machine. (You actually don’t have to shut it down and you still can move ahead with below, but let’s just shut it down.)

In Hyper-V click on Virtual Switch Manager.

image
Virtual Switch Manager
There, create a new External virtual network switch.

8
New External Virtual Switch
In the next step, give a name, I am using External Virtual Switch, and I am selecting my Wi-Fi adapter to be used in virtual switch and allowing sharing as below.

6
External Virtual Switch Properties
Click on Apply and Ok.
10
Network Connections
Once it got created, Right click on vEthernet (External Virtual Switch) connection, click on Properties, go to Sharing tab. Please note that I am not doing any changes here, and I am keeping it as it is. In some articles, they say that you need to tick the checkboxes and do the allowing. There is a scenario, which you really need to enable these, and I am describing that later in the post. Hang on!. So for now, I am keeping this as it is.

15
vEthernet (External Virtual Switch) Sharing
Right click on Ubuntu Virtual Machine and click on Settings. It will look like below.

11
Virtual Machine Settings
Now set the Virtual Switch property to created External Virtual Switch.

12
Virtual Machine Settings
Click on Apply and Ok.

Now start the Ubuntu virtual machine back again and now you should have internet.

Now let’s see what are the Wired Connection properties in your Ubuntu machine. You should be seeing the following. In IPv4 Settings tab, Method is Automatic(DHCP).

17
Wired Connection IPv4 Settings
And when you check Connection Information for Wired Connection, you can see that a IP address is assigned, and the Gateway(Route) and DNS is assigned with your routers settings.

14
Wired Connection Information
Now let’s say, you still don’t have internet for some reason. Here is a workaround.

First go to vEthernet (External Virtual Switch) properties and do the allowing as below.

7
vEthernet (External Virtual Switch) Sharing
Run a ipconfig on command prompt and get the vEthernet (External Virtual Switch) values.

18
ipconfig
In Ubuntu machine, let’s manually configure the IPv4 settings as follows. And of course, you need to replace these with yours.

16
Wired Connection IPv4 Settings
Gateway is the IPv4 address of vEthernet (External Virtual Switch) or you can use the Default Gateway of vEthernet (External Virtual Switch). When you use the IPv4 address of vEthernet (External Virtual Switch), that means you are going out through vEthernet (External Virtual Switch), so you should do the allow sharing on vEthernet (External Virtual Switch) connection. When you use the Default Gateway of vEthernet (External Virtual Switch), that means you are going out through the router and not using the vEthernet (External Virtual Switch). And then of course, you don’t have to do the allow sharing on vEthernet (External Virtual Switch) connection on Windows. So the rule here is, if you are going to use the IPv4 address of vEthernet (External Virtual Switch) as your Gateway here, you need to do the allow sharing on vEthernet (External Virtual Switch) connection on Windows. Here since, I have done the allowing, I am using the IPv4 address of vEthernet (External Virtual Switch) as the Gateway.

For DNS, I am setting as 8.8.8.8 or it can be the same as the DNS of vEthernet (External Virtual Switch) which is 192.168.0.254 in my scenario.

13
Wired Connection Information
So, that’s it. Now you should have Internet.

Internal Virtual Switch

So this is how you can configure the Ubuntu virtual machine with a Internal switch. For this you will have to shutdown the Ubuntu virtual machine and do the following.

Create a new Internal Virtual Switch in Hyper-V. I am naming it as Internal Virtual Switch.

1
New Internal Virtual Switch
Click on Apply and OK.

Open up properties of vEthernet (External Virtual Switch) and do the allow sharing with newly created vEthernet (Internal Virtual Switch).

5
vEthernet (External Virtual Switch) Properties
Open up the properties of vEthernet (Internal Virtual Switch) and inside Internet Protocol Version 4 (TCP/IPv4), make sure the IP Address to look something like below. When I allow sharing of vEthernet (External Virtual Switch) with newly created vEthernet (Internal Virtual Switch), for me the default IP Address of vEthernet (Internal Virtual Switch) was in a different network range. So I have changed it as follows.

3
vEthernet (Internal Virtual Switch) TCP/IPv4 Settings
Change your Ubuntu virtual machines' Network Adapter to Internal Virtual Switch.

2
Ubuntu Virtual Machine Network Adapter
Switch on the Ubuntu virtual machine. Make you’re your connection properties look like below. If Automatic(DHCP) doesn’t give like below, you will have to assign IPv4 Settings manually. For me it was not, so I am in the Manual mode.

4
Wired Connection Properties
Give an IP address, and here the Gateway should be the IP Address of vEthernet (Internal Virtual Switch). DNS Servers can be either, public DNS which is 8.8.8.8 or the IP Address of vEthernet (Internal Virtual Switch) which is 192.168.0.100 for me. So my wired connection summary is like below.

6
Wired Connection Information
Now you should have Internet.

Please note that, sometimes, you will need to disconnect and reconnect the Wired Connection for changes to be effected. Once you got the concept, it’s possible for you to rearrange the above steps to match your need. And of course, rather than starting fresh with no previous Internal/External switches created,  you can start the whole process with previously created Internal/External switches.

Last note, Hyper-V rocks!

Your comments are mostly welcome.

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment