All pastes #492423 Raw Edit

Something

public text v1 · immutable
·published 2007-05-17 05:09 UTC
rendered paste body
I want to take connections for a port on nyl30m-8101:eth0 and nat/forward them to a port on a remote machine accessible only through eth2 on nyl30m-8101

Client 169.37.xxx.xxx ==> server nyl30m-8101 port 8000

server nyl30m-8101
interfaces :
      eth0 169.39.214.10
      eth2 169.39.214.166

Destination 199.168.251.189 port 8603
I thought in order to make this work there would be two rules - one to route the incoming traffic to eth0
And second to route it to the destination address and then back ...

iptables -t nat -A PREROUTING -p tcp -i eth0 -s 169.37.0.0/16 -sport 8000 -j DNAT --to 169.39.214.166:8603
iptables -A FORWARD -p tcp -i eth2 -s 0/0 -d 199.168.251.189 --dport 8603 -j ACCEPT

iptables -t nat -A POSTROUTING -p tcp -i eth2 -d 169.39.214.166 --sport 8603 -j SNAT --to 169.39.214.10:8000
iptables -A FORWARD -p tcp -i eth0 -s 0/0 -d 169.37.0.0/16 --sport 8603 -j ACCEPT


Routes: 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
169.39.214.160  *               255.255.255.240 U         0 0          0 eth2
169.39.214.96   *               255.255.255.224 U         0 0          0 eth1
169.39.214.0    *               255.255.255.192 U         0 0          0 eth0
199.168.251.0   169.39.214.174  255.255.255.0   UG        0 0          0 eth2
169.254.0.0     *               255.255.0.0     U         0 0          0 eth2
default         169.39.214.2    0.0.0.0         UG        0 0          0 eth0