1

I have now spent some time researching, but I haven't found a working solution to the following problem:

I want to tunnel any requests on server 1, port x to server 2, port x. The port stays the same, I just want to tunnel any data being sent to server 1 on port x to server 2.

The connection would look like this:

Client > Server 1 >tunnel> Server 2

and reverse:

Server 2 >tunnel> Server1 > Client

Is that possible? If yes, how? The servers are both running Debian 8.

Please excuse me if this is a total noob question, but I am just getting started with servers and stuff.

Thanks ^^

1 Answer 1

0

This is called Proxy(ing). Yes this is possible by enabling the forwarding module on server1 and then add the appropriate forwarding rules on your iptables.

For example:

*On server1:
Enable Forwading:

echo "1" > /proc/sys/net/ipv4/ip_forward  
sysctl net.ipv4.ip_forward=1  

Add forwarding Rules on Iptables

iptables -t nat -A PREROUTING --dst server1_ip -p tcp --dport portX -j DNAT --to-destination server2_ip:portX
iptables -t nat -A POSTROUTING -p tcp --dst server2_ip --dport portX -j SNAT --to-source server1_ip
iptables -t nat -A OUTPUT --dst server1_ip -p tcp --dport portX -j DNAT --to-destination server2_ip:portX

where:
portX: The port you wish to forward
server1_ip: Server ip which receives initial ip and forwards to server2.
server2_ip: The ip address of the server you wish to forward the traffic to.

2
  • Thank you for your answer. Proxying describes it pretty well. Basically, all traffic being sent to server 1 should be tunneled to server 2 where it is being processed. The response uses the same connection and the same route(so server 1 is only there for passing stuff between the client and server 2, in both directions). Since it is no HTTP traffic, e.g. the apache proxy-mod will not work in this case. May 20, 2016 at 14:54
  • @rocket_doge_ I have updated my answer. Give it a try and see if it works.
    – giomanda
    May 20, 2016 at 15:23

You must log in to answer this question.

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