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

The application client on local machine A ( is connected to the server (, 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 ( 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 -p tcp -m tcp --dport 38xx -j DNAT --to-destination
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


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, 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
$ 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 .