8 bits only: Let’s build a router, part 1

Today I’m going to describe the first steps of how I set up a virtual router, to connect multiple private local access networks of virtual machines together, and eventually, to the Internet.

Obviously, we first need to understand, what is a router? It’s something we all have in our homes, but in the eyes of most, is just a magical tunnel to the Internet.

Your router, visualized

A router is really just a computer, which is specially configured to enable a set of devices to use a shared connection to the public internet (e.g., through a single modem/broadband connection), as well as to communicate with each other, independently of the Internet.

Of course, like always I can’t divulge the entire path to building this router in just this post (partially so you’ll come back for the next part, partially because I haven’t finished this experiment myself!). Today we’ll make some headway on configuring our router and virtual networks, and on the way will learn about setting up Linux VMs, virtual networks, and network interface configuration.

VM Setup

There’s countless articles on the internet for how to set up an Ubuntu VM using Hyper-V, such as this one, so I won’t drone on about this step, I’ll just specify the exact VMs I am setting up for my configuration, and briefly, the virtual networks.

Private Network Setup

For my network configuration, I’ve set up 3 isolated networks, each including a pair of VMs, connected to each other by a virtual switch. A switch is simply an input-output device, which routes traffic to and from hosts connected to the switch, via ethernet. You may have seen a switch like below before in your home or work network setup, creating a network of devices connected to the switch via ethernet cables.

Goodbye bulky switch, hello virtualization!
Adding a network adapter for a VM in the blue network, connecting it to the blue switch

A network adapter is a hardware component of your computer which allows it to access a computer network, via a link-layer protocol. A common example that most would be familiar with is a Wi-Fi network adapter, which manages a device’s ability to access Wi-Fi networks.

In our case, we are configuring ethernet network adapters, which manage a device’s ability to access a network via ethernet. By configuring an ethernet network adapter for a VM onto a particular virtual switch, we can imagine an ethernet cable running from this computer, into the switch, similar to the picture below.

Visualizing the Network

At this point, we have configured 3 switches, Red, Green, and Blue, and configured our 6 VMs to each have a virtual ethernet connection to their respective switches.

Hooking up the router

4 network adapters for our router, 1 per private network, 1 for the Internet

We have a network!

We now have a fully formed ethernet/L2 network configuration, with switches hooking up each of our VLANs to the router, and a switch connecting the router to the Internet, which we can refer to as a switched ethernet.

4 ethernet interfaces on our router, 1 per private switch, 1 to access the Internet

Getting some IP

You may be asking at this point, are we done? We have addresses to identify network interfaces, and a channel through the switch configuration that lets the router route traffic between our networks, and to the Internet, right? In theory, we could, and this ethernet configuration could suffice (at least to connect our private networks), but in practice, it’s a bit more complex than that, as the Internet is driven by a protocol which builds on top of what we’ve got so far, known as IP.

To reach our goal of building a router as we know it, we’ll need to take the next step, and learn how to configure IP addresses for our network interfaces, as well as IP routing, both of which we’ll talk about next time.



Working on storage management and infrastructure at Azure SQL

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store