IP/PORT forward requests to another server

Posted by DT.DTDG on Ask Ubuntu See other posts from Ask Ubuntu or by DT.DTDG
Published on 2014-08-19T04:06:18Z Indexed on 2014/08/19 4:32 UTC
Read the original article Hit count: 253

I have the following listening PORT:IP set up on my UBuntu server.

12.345.67.890:3636

It receives requests perfectly, however, I would now like to forward any requests to that IP:PORT to another IP:PORT, i.e.:

09.876.54.321:3636

Essentially I want to do a request forward 12.345.67.890:3636 -> 09.876.54.321:3636.

How can I go about it in Terminal and if I wanted to change it back how can I go about that too? Is there also a way to test that the data is forwarding and it is setup properly?

Thanks!

Edit: Can I just do as follows, just wondering how I would go about testing it and how I could disable it?

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 3636 -j DNAT --to-destination 09.876.54.321:3636
iptables -t nat -A POSTROUTING -j MASQUERADE

© Ask Ubuntu or respective owner

Related posts about networking

Related posts about server