Homelab: Host as a router

Let’s see how to turn a host into a router.

For this purpose, I have two VMs – Ubuntu-VM and Ubuntu-VM Clone.

Let’s say we want to turn Ubuntu-VM into a router. To be able to do that, two NICs have to be enabled and put in two different subnets and ip-forwarding should be enabled on Ubuntu-VM. Remember to have the interfaces on VMs in bridged mode.

Fig 1: Two Ubuntu-VMs
Fig 2: On Ubuntu-VM, turn on Adapter 2; Enable bridged mode on all interfaces

Network setup should look something like this, see Fig 3:

Fig 3: Network Diagram

Once you configure all the interfaces, check internet connectivity on the host (Ubuntu-VM Clone)

Fig 4: Shows that the host has no Internet

At this point, we have to enable ip forwarding on our router host and add some rules to netfilter/iptable.

Fig 5: On Router host, enable ip forwarding by setting /proc/sys/net/ipv4/ip_forward to 1
Fig 6: Firewall rules on router host

It is convenient to make a bash script like the one above.
Host might not still have DNS. You would have to edit /etc/resolv.conf to add “nameserver 8.8.8.8” (8.8.8.8 being Google’s public DNS). Let’s see if our host has internet now.

Fig 7: Host is setup successfully.

It also means that router host is forwarding packets from its external interface to internal interface. One of the functions of a router has been accomplished.




References:
1. Jungwoo Ryoo’s topic on LinkedIn Learning – Host as a router