Created
November 2, 2018 11:26
-
-
Save mgax/a3e3f464010b01bfd95a8e25f75b697e to your computer and use it in GitHub Desktop.
Forward web traffic to backend server
This file contains 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/bash -e | |
PROXY=$(curl -s ipinfo.io/ip) | |
BACKEND="(dig +short example.com) | |
set -x | |
iptables -t nat -F | |
iptables -t nat -A PREROUTING -p tcp --dport 80 -d $PROXY -j DNAT --to $BACKEND:80 | |
iptables -t nat -A PREROUTING -p tcp --dport 443 -d $PROXY -j DNAT --to $BACKEND:443 | |
iptables -t nat -A POSTROUTING -d $BACKEND -j MASQUERADE | |
echo 1 > /proc/sys/net/ipv4/ip_forward |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment