← All articles
Date Published: May, 2026

Routing with Router

Objective: In this we are going to create a router and connect all the other machines to this router and explore related things.

Before proceeding, create another virtual machine to setup DNS and add it to our private network.

Table Of Contents

  1. What is Internet?
  2. What & Why Routers?
  3. Example Explained
  4. Setting up the router
  5. Connecting others to router
  6. Conclusion

What is Internet?

Internet can be thought of as a network of networks. Contrary to the popular belif, the entirity of the internet is wired not wireless. Let us first understand how the whole infrastructure work and how someone sitting in Asia can talk to someone sitting in Australia via internet.

At your home, you may have a router to provide you with internet access. You would observe that a wire comes out of the router which connects to a light pole or connects with other wires.

Your Router, it connects to the local Central Office of your local Service Provider. Your local service provider has purchased a connection to a national service provider. Your Local ISP forwards your packets to the national service provider which forwards your requests to the destination it is supposed to go to.

Now all this forwarding your packets, it is accomplished via routers. There are networks of networks of routers. All the transfer takes via physical cables whether it be figber optic or copper cables or transoceanic cables.

Thus, routers play a critical role in the modern infrastructure.

What & Why Routers?

Routers are a Layer 3 device which means they deal with IP addresses unlike a switch which is a Layer 2 device which deals only with MAC addresses. A Routers job is to accept incoming packets and transmit it to the suitable destination, determined by its internal routing table.

The Router we see in our homes is a gateway router which is an all in one device that performs the job of multiple other devices. Whereas the actual, standalone routers is a single device whose sole job is to route a packet from one port to another according to its routing table. Let us talk in a bit depth about our home routers.

Our home router or gateway routers contains wirelass access points, switch, router and modem. The Wireless Access Points is the one to which we connect to, we can recognise the WAP by the ssid or the name which appears when we try to connect to wifi.

The WAP or WAPs connects to the switch which allows for communication between the devices connected to the WAPs. The switch then connects to router which decides where to send the packet to. Then router is connected to modem which converts the digital signal to electrical signals for the wires to carry it out.

Example Explained

To understand this better we will use a tool called traceroute.

Application dashboard
Traceroute example

Let us explore this output hop by hop.

We could use another tool called mtr. Perhaps you should try to decode the output by your own.

Application dashboard
mtr example

Setting up the router

Before we setup the router, it is imperative that you understand how iptables work. click here to read about it.

The first step is to enable packet forwarding so that packets recived on the enp0s8 interface which is a part of internal network is forwaded to enp0s3 which provides us access to internet.

shell

                $ sysctl -w net.ipv4.ip_forward=1
                $ cat /proc/sys/net/ipv4/ip_forward
  

Then using iptables we can set it up to act as a router ( NAT )

shell

                $ iptables -t NAT -A POSTROUTING -o enp0s3 -j MASQUERADE
  

And here we have our router.

Connecting others to router

To connect other machines to our router, we simply configure the netplan config.

Note: Default gateway refers to our router. For eg 192.168.1.1 is the default gateway, an internal interface for other devices to send packets to.

text

                network:
                    ethernet:
                        enp0s8:
                            addresses:
                                - 10.2.0.20/24
                            nameservers:
                                addresses:
                                    - 10.2.0.20
                                search:
                                    - lab.local
                            routes:
                            - to: default
                              via: 10.2.0.1 ( the ip of the vm acting as router )
                            dhcp4: false
                            dhcp6: false
                    version: 2

Conclusion

In this article we set up a router and connected other machines to this router. Also we explored some other tools and understood how routers and internet works.

Note: In this writeup we didn't explore things like NAT, private IP addresses and classless subnetting. You can explore this on your own or read here.