Build router internet gateway on ubuntu linux
build internet gateway on linux is prety easy, you just need minimum two nic and less configure to enable internet gateway, first you need to configure ip address on each nic then enable forwading packet and configure iptables to translate source address comes from your local to nic internet
hope this article help you
Step by step
- set each nic
- enable forwarding packet
- set iptables to translating source adress
1. set nic ipaddress
let say you have ip 192.168.1.1/24 for internet side (eth0) and 192.168.100.1/24 for local side (eth1) execute this two command on your terminal
"ip addr add 192.168.1.1/24 dev eth0" for internet side "ip addr add 192.168.100.1/24 dev eth1" for lan side
you can make it permanent when you fill above script to rc.local file
2. enable forwarding packet
execute "vi /etc/sysctl.conf" find this, and should set to 1 "net.ipv4.ip_forward = 1" after save file, then execute this to make permanent "sysctl -p"
3. set iptables to translating source adress
execute this two command "iptables -I FORWARD -o eth0 -j ACCEPT" to accept all forwarding packet "iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE" or "iptables -t nat -I POSTROUTING -o eth0 -j SNAT --to-source 192.168.1.1" to translate all incoming packet source address to internet nic address
yes you can make it permanent when you fill above script to rc.local file
that's it, you have internet gateway who forward all trafic to eth0 and translate local lan source address to nic ip address, you can test it ping to www.google.com from client side, and dont forget set default gateway to 192.168.100.1 on client side and set your proper dns address
i dont create the image, i got from vecta.io and pngkey.com