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

What is IP

The Internet Protocol, known as IP, is a software layer which builds on top of L2 networking, implementing several key capabilities on top of what L2 networking provides. The defining achievement of IP is what is typically referred to as packet switching, which is the process of routing discrete chunks of data, known as packets, from a source machine to its destination, spanning multiple L2 networks, allowing machines not physically connected to the same network to be able to communicate with each other.

IPv6 packet header breakdown
datagram packet switching

How does IP work?

At its core, the Internet as we know it is a web of physical networks such as the one, we have been tasked with building, where at least one machine in each of these networks is serving as a router, and is connected to another networks, creating a bridge between these networks over which data can flow, and all together, forming a globally interconnected network.


Subnets are one of the keys to routing IP traffic efficiently and easily. We can define a subnet as a range of IP addresses, which results from applying a 32-bit (for IPv4) subnet mask to an IP address (using a bitwise AND operation between the IP address and subnet). For example, consider the following IP address the subnet mask For this subnet, when we apply a bitwise AND operation between it and any IP address, the result will leave the entire IP address unchanged but the last 8 bits (or single number in dot notation). This subnet mask thus defines a set of subnets of IP addresses where the first 24 bits (or 3 numbers in dot notation match). For example, the subnet (where /24 is a shorthand way of saying the first 24 bits of the subnet mask are 1 -> is the set of IP addresses which start with 192.168.2.

e.g. Creating two distinct ranges of IP addresses from one by using subnetting

That’s all great, but…..

The important takeaway, and the next step of our puzzle is the following: We now know that the Internet is formed by internetworking of physical networks, with routers that handle the switching of packets between these networks. We also know that these routing decisions are based on IP addresses, which identify hosts and help routers decide whether they can send packets to a destination in their physical network, or whether they should forward them to another router, the question we now need to answer is how do we get IP addresses for our hosts?

Static IP and DHCP

The answer to our question is that we can either assign an IP address to our interfaces manually, or we can have one dynamically configured. The latter is the de facto approach used for most devices, and the protocol which is used to dynamically assign these addresses is known as DHCP, or dynamic host configuration protocol.

Traffic to addresses of form 192.168.0.* to eth1

Traffic to addresses of form 192.168.1.* to eth2

Traffic to addresses of form 192.168.2.* to eth3

We can bring up each of the interfaces we have configured using

sudo ifup <interface name>

and after we do so, end up with a set of interfaces like below

A router using a router to be a router…

Setting up a DHCP server

We can install DHCP on Ubuntu via

sudo apt install isc-dhcp-server.

Once we have done so, we will rely on 2 key configuration files to set up our DHCP server.

It’s also worth noting that IP addresses assigned by each interface will be in the same subnet as that network interface. (e.g. interface assigns IP addresses of form 192.168.1.*, same for other two interfaces). This is important because it means any traffic intended for the interfaces assigned these IPs which goes to our router will be forwarded to the switch shared by those interfaces and the router, because of our earlier configuration of the subnets for each of the router’s network interfaces, which routes all traffic in the subnet to the corresponding interface.

Once we have configured the behavior of our DHCP server, we must configure /etc/default/isc-dhcp-server, like below, to specify the interfaces to listen on for DHCP requests:

Sudo systemctl restart isc-dhcp-server

We will see output in journalctl like below, showing the interfaces we are listening on for DHCP requests, and some other configuration information

Is that it?

Obviously not! If you think it was that easy then you don’t know the firs thing about writing a blog series (hint: there’s usually more than 2 parts). Let’s take stock of where we are at now though, we have:

Looking Forward

So far, we have been able to set up a scheme to assign and identify interfaces by IP addresses, either statically or dynamically. The unfortunate reality however is we are still a bit away from being able to communicate across networks as we described that IP allow us to do. Next time we’ll continue to extend our usage of IP to solve this problem, and continue on our way to building a router.



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
Aashray Anand

Aashray Anand

Working on storage management and infrastructure at Azure SQL