Create a basic Linux Router
Article is based on Ubuntu 16.04 built on ESXi 6.5
Linux Commands Used:
route
iptables
tcpdump
Create a Multi-NIC Virtual Machine
![](https://theoryit.com/wp-content/uploads/2018/12/linux_router1.png)
Configure all interfaces with Separate Networks
![](https://theoryit.com/wp-content/uploads/2018/12/linux_router2.png)
Set default route with a metric of 0 for the ‘WAN’ side NIC
Example Command:
sudo route add default gw 10.1.1.1 metric 0
Set default route with metric of 1 point to the WAN NIC
Example Command:
sudo route add default gw 10.1.1.22 metric 1
Set IPtable to NAT traffic to the WAN NIC IP (reference link)
Example Command:
iptables -t nat -A POSTROUTING -o ens160 -j MASQUERADE
Set IPtables to allow forwarding
Example Command:
iptables -A FORWARDING -j ACCEPT
Set network to enable IP forwarding
Temporary command:
systctl -w net.ipv4.ip_forward=1
Permanent method:
– Go to /etc/sysctl.conf
– Uncomment the line for net.ipv4.ip_forward
– Change the value from 0 to 1
– then exit file and run command sysctl -p /etc/sysctl.conf
should show the change made
Test and make sure that a device behind one of the other Links is successfully going through the linux router, if need use tcpdump -i ens192 to look at all traffic flowing through the interface.