docker/ipnat/build/iptables.sh

28 lines
723 B
Bash

nat () {
# All traffic to $THIS_PORT on this container
# will be redirected to $THAT_PORT on $THAT_IP
$THAT_IP=$1
THIS_PORT=$2
THAT_PORT=$3
# Accept forward incoming traffic
iptables -I FORWARD -d $FWD_IP -m tcp -p tcp --dport $THAT_PORT -j ACCEPT
# Accept forward return traffic
iptables -I FORWARD -s $FWD_IP -m tcp -p tcp --sport $THAT_PORT -j ACCEPT
# Redirect packets to remote
iptables -t nat -I PREROUTING -m tcp -p tcp --dport $THIS_PORT -j DNAT --to-destination $THAT_IP:$THAT_PORT
}
NAT_IP=10.143.0.20
nat $NAT_IP 33 10013
nat $NAT_IP 993 10015
nat $NAT_IP 587 10016
# Include this line ONCE, at the end.
iptables -t nat -I POSTROUTING -d $FWD_IP -j MASQUERADE