Skip to content

Instantly share code, notes, and snippets.

@mgax
Created November 2, 2018 11:26
Show Gist options
  • Save mgax/a3e3f464010b01bfd95a8e25f75b697e to your computer and use it in GitHub Desktop.
Save mgax/a3e3f464010b01bfd95a8e25f75b697e to your computer and use it in GitHub Desktop.
Forward web traffic to backend server
#!/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