0

I'm trying to redirect a server's incoming TCP packets to local machine B.

The application client on local machine A (192.168.0.7) is connected to the server (1.2.3.4), so every incoming TCP packet from the server arrives at local machine A on port 38xx.

  1. How can I redirect the packets from the server to local machine B (192.168.0.20) instead of local machine A?
  2. How can I then send the packets back to the server from local machine B but make it seem that it was coming from local machine A?

I have tried the following:

  • Enabling port forwarding by editing the sysctl.conf file.
  • Running the IP tables command:
iptables -t nat -A PREROUTING -d 192.168.0.7 -p tcp -m tcp --dport 38xx -j DNAT --to-destination 192.168.0.120:38xx
iptables -t nat -A POSTROUTING -j MASQUERADE

However, analyzing the traffic with Wireshark doesn't seem to bring up any results.

Thank you kindly.

1 Answer 1

0

Forward Traffic: [client] --> [proxy] --> [server-A] --> [server-B]

Return Traffic: [server-B] --> [server-A] --> [proxy] --> [client]

If this is what your traffic flow should look like, then you have to configure server-A to forward and masquerade traffic. When server-A receives traffic from proxy, it will forward to server-B.

While server-B has an IP of 192.168.0.20, let's assume the following on server-A:

eth0 is facing the proxy
eth1 is facing server-B
TCP 3800 is listening on server-A and server-B respectively

On server-A, do the following:

$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
$ sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3800 -j DNAT --to-destination 192.168.0.20:3800
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .