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

route add default gw

check ping now


and add nameserver

echo “nameserver” > /etc/resolv.conf 

all done šŸ™‚