Skip to content

Instantly share code, notes, and snippets.

@rogerbush8
Last active August 29, 2015 14:17
Show Gist options
  • Save rogerbush8/048d17eec71da6a09fbf to your computer and use it in GitHub Desktop.
Save rogerbush8/048d17eec71da6a09fbf to your computer and use it in GitHub Desktop.
configure-linux-as-nat-rhel
# This script configures a linux box as a NAT router (PAT), suitable for use
# for AWS instances in a VPC Private Subnet to communicate with the Internet
#
# To setup a NAT:
# # Create an AWS instance in Public Subnet
# # Disable src./dest. check (networking menu in UI)
#
# To install, login to instance:
# sudo su -
# curl http://gist.github.com/.../raw/... | bash -s
#
cd /root
yum -y update
yum -y update aws*
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
/sbin/iptables -t nat -A POSTROUTING -o eth0 -s 0.0.0.0/0 -j MASQUERADE
/sbin/iptables-save > /etc/sysconfig/iptables
mkdir -p /etc/sysctl.d/
cat <<EOF > /etc/sysctl.d/nat.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.send_redirects = 0
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment