Skip to content

Instantly share code, notes, and snippets.

@bastosmichael
Last active December 30, 2015 12:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastosmichael/7830661 to your computer and use it in GitHub Desktop.
Save bastosmichael/7830661 to your computer and use it in GitHub Desktop.
Ubuntu NAT setup between eth0 and eth1
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 10.1.250.179
netmask 255.254.0.0
gateway 10.1.100.63
dns-nameservers 128.49.4.2 128.49.4.3
#!/bin/bash
if [ $# -eq 0 ]
then
echo "nat.sh [options] install
install - Should be run once initially"
elif [ $1 == 'install' ]; then
echo "Flush all the rules in filter and nat tables..."
sudo iptables --flush
sudo iptables --table nat --flush
sudo iptables --delete-chain
echo "Delete all chains that are not in default filter and nat table..."
sudo iptables --table nat --delete-chain
echo "Set up IP FORWARDing and Masquerading..."
sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
sudo iptables --append FORWARD --in-interface eth1 -j ACCEPT
sudo iptables --append FORWARD --in-interface eth1 -j ACCEPT
echo "Enables packet forwarding by kernel..."
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
echo "Apply the configuration..."
sudo iptables-save
echo "For List the iptables rules"
sudo iptables -L
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment