Let's say you have two TCP/IP subnet in your house, and you want to route network traffic between them.
You probably wouldn't do this on your main gaming/internet browsing computer. So, let's say you have another
computer with Linux on it, and this computer has two ethernet ports ( it doesn't matter if they are USB adapters ).
You probably wouldn't do this on your main gaming/internet browsing computer. So, let's say you have another
computer with Linux on it, and this computer has two ethernet ports ( it doesn't matter if they are USB adapters ).
- Assign IP Addresses: Ensure each Ethernet port on your Linux computer has an IP address from each subnet. For example:
- eth0: 10.0.0.1
- eth1: 192.168.0.1
- Enable IP Forwarding: This allows the Linux kernel to forward packets between interfaces. Edit the /etc/sysctl.conf file and set:
Code:
net.ipv4.ip_forward = 1
Code:sudo sysctl -p
- Configure Routing: Add routing rules to ensure packets are directed correctly. You can use iptables for this:
Code:
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
- Persist the Configuration: Save the iptables rules so they persist after a reboot. This can be done using iptables-save:
Code:
sudo iptables-save > /etc/iptables/rules.v4
- Set Up Default Gateways: Ensure devices on each subnet use the Linux computer as their default gateway. For example:
- Devices on the 10.0.x.x subnet should use 10.0.0.1.
- Devices on the 192.168.x.x subnet should use 192.168.0.1.