Wednesday, April 11, 2018

How can I setup a Linux NAT Router in Ubuntu?


1. Enable packet forwarding for IPv4 between NICs:

  • Open and edit /etc/sysctl.conf
  • Ucomment net.ipv4.ip_forward=1
  • To execute command sysctl -p
2. Create a postrouting rule within iptables:

  • iptables -t nat -A POSTROUTING -o enp0s8 -s -j MASQUERADE
  • Where enp0s8 is WAN and is LAN, please modify those parameters depend on your environment.
3. Save and restore iptables rule after reboot:

  • Save rules: iptables-save > /etc/
  • Restore rules:
  • Open and edit /etc/network/interfaces to add pre-up.....

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
pre-up iptables-restore < /etc/


    No comments: