Skip to content

Instantly share code, notes, and snippets.

@mRoca
Created December 5, 2017 10:37
Show Gist options
  • Save mRoca/0e6a6aef67058f89ae0e2591e4bca1d7 to your computer and use it in GitHub Desktop.
Save mRoca/0e6a6aef67058f89ae0e2591e4bca1d7 to your computer and use it in GitHub Desktop.
iptables forward / proxy - ec2
#!/bin/sh
# This script must be added in the "User Data" field of the ec2 instance configuration
service iptables start
iptables -F
iptables -t nat -F
iptables -t mangle -F
echo 1 > /proc/sys/net/ipv4/ip_forward
ip=$(getent hosts my-domain.name | awk '{ print $1 }')
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3306 -j DNAT --to ${ip}:3306
iptables -A FORWARD -p tcp -i eth0 --dport 3306 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment