NAT
Set up DNAT to forward with client source IP. (You may need a private tunnel as most IDCs have route filter)
- Gateway - `eth0` public: `8.7.6.5` - `tun0` private: `10.1.1.1`- Backend - `eth0` public: `8.7.6.4` - `tun0` private: `10.1.1.100`On gateway:
Section titled “On gateway:”iptables -t nat -I PREROUTING -p tcp -i eth0 --dport 8080 -j DNAT --to-destination 10.1.1.100:8080On backend:
Section titled “On backend:”IP Rules for special routed server
Add a table name to /etc/iproute2/rt_tables
Section titled “Add a table name to /etc/iproute2/rt_tables”10 origAdd IP Rule, assuming main IP is 10.1.1.100, gateway is 10.1.1.1 (As above)
Section titled “Add IP Rule, assuming main IP is 10.1.1.100, gateway is 10.1.1.1 (As above)”Set default route when traffic coming from NAT
ip rule add from 10.1.1.100 lookup origip route add default via 10.1.1.1 table origOR you can add default route with default tun0
ip route add default dev tun0 table origDNAT & SNAT
Section titled “DNAT & SNAT”Use this if you do not need to forward client source IP.
On gateway:
iptables -t nat -I PREROUTING -p tcp -i eth0 --dport 8080 -j DNAT --to-destination 10.1.1.100:8080iptables -t nat -I POSTROUTING -p tcp -o tun0 -j SNAT --to-source 10.1.1.1Reference: