IP Forwarding: Bridging Two Wired Networks with Three Isolated Machines
In this article, we will explore the concept of IP forwarding and how to connect two wired networks using three isolated machines. We will be using a fresh Ubuntu 22.04 LTS installation on all three machines. The goal is to create a network topology where the three machines are connected to two separate networks, and IP forwarding is used to enable communication between the networks.
Network Topology
The network topology for this article is as follows:
- Machine 1: Left network, IP address 192.168.1.2/24, gateway 192.168.1.1
- Machine 2: Isolated network, IP address 192.168.2.1/24, no gateway
- Machine 3: Right network, IP address 192.168.3.1/24, gateway 192.168.3.254
The goal is to enable communication between the left and right networks through the isolated network using IP forwarding.
IP Forwarding
IP forwarding, also known as IP routing, is the process of forwarding IP packets from one network to another. This is typically done by routers, but in this case, we will be using the isolated machines as routers to forward packets between the left and right networks.
To enable IP forwarding on Ubuntu, we need to modify the kernel settings. This can be done by editing the /etc/sysctl.conf file and setting the net.ipv4.ip\_forward parameter to 1:
sudo nano /etc/sysctl.conf
net.ipv4.ip\_forward = 1
After making this change, we need to reload the sysctl configuration:
sudo sysctl -p
Setting Up the Network Interfaces
On each machine, we need to configure the network interfaces to match the network topology. We will assume that each machine has two network interfaces: one connected to the left network, and one connected to the isolated network.
On Machine 1, we need to set the left network interface to 192.168.1.2/24 and the isolated network interface to 192.168.2.1/24. This can be done using the following commands:
sudo nano /etc/network/interfaces.d/eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
sudo nano /etc/network/interfaces.d/eth1
iface eth1 inet static
address 192.168.2.1
netmask 255.255.255.0
On Machine 2, we need to set the isolated network interface to 192.168.2.2/24. This can be done using the following command:
sudo nano /etc/network/interfaces.d/eth0
iface eth0 inet static
address 192.168.2.2
netmask 255.255.255.0
On Machine 3, we need to set the isolated network interface to 192.168.2.3/24 and the right network interface to 192.168.3.1/24. This can be done using the following commands:
sudo nano /etc/network/interfaces.d/eth0
iface eth0 inet static
address 192.168.2.3
netmask 255.255.255.0
sudo nano /etc/network/interfaces.d/eth1
iface eth1 inet static
address 192.168.3.1
netmask 255.255.255.0
gateway 192.168.3.254
Enabling IP Forwarding on the Isolated Machines
Now that we have configured the network interfaces, we need to enable IP forwarding on the isolated machines (Machine 2 and Machine 3). This can be done using the following commands:
sudo sysctl -w net.ipv4.ip\_forward=1
We also need to configure the routing tables on the isolated machines to forward packets between the left and right networks. This can be done using the following commands:
sudo ip route add default via 192.168.1.1 dev eth0
sudo ip route add 192.168.3.0/24 via 192.168.2.1 dev eth1
On Machine 3, we need to add a route to the left network:
sudo ip route add 192.168.1.0/24 via 192.168.2.2 dev eth0
Testing the Network
Now that we have configured the network, we can test communication between the left and right networks. From a machine on the left network, we should be able to ping a machine on the right network:
ping 192.168.3.1
If this is successful, then IP forwarding is working correctly and packets are being forwarded between the left and right networks through the isolated machines.
In this article, we have explored the concept of IP forwarding and how to bridge two wired networks using three isolated machines. We have covered the following key concepts:
- IP forwarding and routers
- Setting up the network interfaces on each machine
- Enabling IP forwarding on the isolated machines
- Configuring the routing tables on the isolated machines
- Testing the network