iptables
Reference manpage: man iptables
Deactivate firewall: Clear iptables rules and accept all traffic.
iptables-restore << EOF > *raw :PREROUTING ACCEPT [461477:823976242] :OUTPUT ACCEPT [0:0] COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT *nat :PREROUTING ACCEPT [104281:12249471] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [3109:273082] :POSTROUTING ACCEPT [3080:270727] COMMIT EOF
Make router from linux machine
Assuming empty or rules allowing routed traffic to get trough iptables.
Allow IPv4 forwarding and masquerade transiting packets.
echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING ! -d 127.0.0.1 -j MASQUERADE