Created
December 5, 2017 10:37
-
-
Save mRoca/0e6a6aef67058f89ae0e2591e4bca1d7 to your computer and use it in GitHub Desktop.
iptables forward / proxy - ec2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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