[<<][pool][>>][..]
Wed Nov 23 10:18:25 EST 2011

Port forwarding

I keep forgetting how this works in raw iptables. From [1]:

  /sbin/iptables \
     -t nat -A PREROUTING -p tcp -i eth0 -d xxx.xxx.xxx.xxx \
     --dport 8888 -j DNAT --to 192.168.0.2:80

  /sbin/iptables \
      -A FORWARD -p tcp -i eth0 -d 192.168.0.2 --dport 80 -j ACCEPT

So this gives something like this:

  # tcp_forward <from-port> <to-host> <to-port>
  tcp_forward () {
      $IPTABLES -t nat -A PREROUTING -p tcp -i $INTERNET --dport $1 -j DNAT --to $2:$3
      $IPTABLES -A FORWARD -p tcp -i $INTERNET -d $2 --dport $3 -j ACCEPT
  }



[1] http://www.hackorama.com/network/portfwd.shtml




[Reply][About]
[<<][pool][>>][..]