How to make ubuntu , debain as router

Hi , lets say you have head-node with two network interfaces like

eth0—> Private

eth1–> Public 

On Head node do like this : 

nano /etc/sysctl.conf

 

net.ipv4.ip_forward = 1

net.ipv6.conf.all.forwarding = 1

 

and run

sysctl -p

add iptables rules on head node 

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

On Private node do like this : 

add route default to headnode private interface for e.g. if head node private ip is 192.168.1.21

route add default gw 192.168.1.21

check ping now

#ping 8.8.8.8

and add nameserver

echo “nameserver 8.8.8.8” > /etc/resolv.conf 

#ping google.com 
all done šŸ™‚