Creating a (VERY) Basic Router for a Hyper-V Private Network – Part Three: Configuring Ubuntu as a Router


In Part One, I created the virtual switches to create a lab network that looks kind of like this:

Goal Virtual Network.png


In Part Two, I installed Ubuntu Linux on a virtual machine.

To finish the project, I need to do a few things:

  • Add a second network interface to the VM
  • Add a route on the firewall
  • Configure networking
  • Enable routing
  • Update the OS
  • Optimize it for virtualization

Adding a Second Network Interface to the VM

During the creation of the VM, I assigned the network adapter to the private virtual switch.  Now, I need to add the external virtual switch so it can route between the two.

Open Hyper-V Manager, select the Virtual Router VM and select “Settings” in the Action Pane:

Hyper-V Mgr.png

In the left pane, under “Hardware”, select “Add Hardware”.  In the right pane, select “Network Adapter” and then lick “Add”:

Add Network Adapter.png

Select the external virtual switch and click “OK”:

Adapter Settings.png

At this point, I can start the VM and perform some initial updates and optimization, but first we need to configure network connectivity.

Add Route on the Firewall

The logical network looks like this:


The firewall needs to know how to get traffic back to the private virtual network.  So, I entered the following route into the firewall:

route inside

(It might be different for your firewall. YMMV.)

Configuring Networking on Ubuntu Linux

When you first start the VM after adding the second adapter, you’ll probably get a window asking to revert to the previous checkpoint.  Just continue and don’t revert.

Log into the VM using the username and password configured during installation:

Logon to VM.png

The first command I’ll run is simply used to see what network interfaces are recognized.  This can sometimes be a a little flaky in Ubuntu.  The command for this is “ifconfig -a”.  The “a” switch shows all interfaces, regardless of whether any are in an up or down state.

Run “ifconfig -a” on the VM:

ifconfig -a.png

All three interfaces are there, which is a relief.  The loopback interface might be a surprise to you, but this interface exists by default and is, obviously, assigned the loopback address ‘’.

The first interface was created and configured during installation and is named ‘eth0’.  It would be nice to see if it actually works, so I’m going to test connectivity by pinging another VM on the same virtual switch.  The server’s IP is

Ping another VM on the virtual switch:

ping VM test.png

You’ll see where the first attempt failed; I had to disable the Windows firewall on the other VM.  Once I did that, I was able to ping both ways.

The second interface is the one we just added via Hyper-V Manager and its name is ‘eth1’.  It has no configuration, so that needs to happen now.  Again, the logical network will look like this:


The network is the private virtual switch (obviously, I hope) and the network is the external virtual switch.  The interface ‘eth0’ is configured correctly for the the private network and I’ll configure the external network as follows:

IP Address:
Subnet Mask:

To do this, I’ll edit /etc/network/interfaces using the nano text editor.  Since it’s a system file, I’ll need to run this with elevated privileges using ‘sudo’ and enter my password.

Issue the command ‘sudo nano /etc/network/interfaces’ and edit the text file:

nano interfaces.png

I modified the comments to make them more meaningful to me.  I also added the section for interface ‘eth1’.  Next, I need to bring the interface up and then restart the network.

Issue the commands ‘sudo ifconfig eth1 up’ and ‘sudo /etc/init.d/networking restart’:

ifconfig and restart.png

Test connectivity by pinging the firewall on the external network:

test external.png

I love it when things actually work.  But, can I ping all the way to the internet?

test external.png

Yep.  ‘Woot’, and all that.  Now, I can update the OS and configure routing.

Configuring Routing on Ubuntu Linux

This part is very easy.  One command and a reboot.

Edit /etc/sysctl.conf and uncomment the line ‘#net.ipv4.ip_forward=1’ by removing the ‘#’.  Then save the file, and reboot:

edit sysctl.png


After the reboot, I tested routing by attempting to ping an internet address from the server on the private virtual switch:

ping from server.png


Updating Ubuntu Linux

One thing I forgot to do was configure DNS on either of the interfaces.  I’ll do that now by editing /etc/network/interfaces.

Edit /etc/network/interfaces and then save the file, and restart networking.  Then test using ‘dig’ and a well-known site:

restart after nameservers.png

test DNS.png

Now, I can update the OS.

The first command used is ‘apt-get update’.  This doesn’t actually apply updates.  Rather, it’s used to update the local list of packages and dependencies from the repositories.  You’ll have to do this before you actually apply updates.

Issue ‘sudo apt-get update’ command (make sure you use sudo… you’ll see errors at the top where I forgot):

apt-get update.png

Next, I’ll install the system patches and upgrades with ‘apt-get dist-upgrade’.

Issue ‘sudo apt-get dist-upgrade’ command (again, I forgot to use sudo… apparently, because I’m stupid):

apt-get dist-upgrade.png

A list of new packages and package upgrades are shown.  You can accept or reject them.  This is one of the things people rave about with Linux… you have all this control.  Blah, blah, blah.  I’ll accept the changes and let it do the upgrades.

apt-get dist-upgrade confirm.png

This could take a while.  After that, I’ll install package patches and upgrades using ‘apt-get upgrade’.

Issue ‘sudo apt-get upgrade’ command (Hey!  I remembered to sudo!):

apt-get upgrade.png

Looks like everything is up-to-date, so on to installing some virtualization packages.

Optimizing Ubuntu for Virtualization

For information regarding what virtualization tools are supported in Hyper-V, Microsoft has published some good info.

According to Microsoft, we want to perform the following operations:

  1. Disable Network Manager
    This isn’t running, so no worries here.
  2. Install the virtual HWE kernel
    Issue the command ‘sudo apt-get install linux-virtual-lts-xenial’

    apt-get install linux-virtual-lts-xenial.png

  3. Install the Hyper-V daemons for VSS Snapshot, KVP and fcopy.
    Issue the command ‘apt-get install linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial’.

    apt-get install more daemons.png

That’s it!  All done and ready for lab work.  Hope you find this useful!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s