0

if we have two server let's say server1(92.92.92.92) server2(76.76.76.76).

I'm working on redirect incoming traffic on server1 port 4444 to server2 port 12345,this is easy with iptables rule on server1 like the following:

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 4444 -j DNAT --to-destination 76.76.76.76:12345
iptables -t nat -A POSTROUTING -j MASQUERADE  

this working well

request --> 4444:server1 <===> 12345:server2

what I need to do is using tor netwok between the two server:

request --> 4444:server1 <===> |tor network| <===> 12345:server2

how I can do what?

I tried to use HiddenServicePort on server2 but I can't forward traffic from HiddenServicePort to another tor hostname ( in server1)

also how i can redirect traffic from iptables to tor specific hostname (server2 hostname)

0

This looks like something to use socat, not iptables.

You need to employ socat on server1 to listen on specific port and forward traffic to server2 through tor. Something along the lines:

socat TCP-LISTEN:4444 SOCKS4A:localhost:server2:12345,socksport=9050

The above command assumes tor running on server1 on the usual port 9050.

You may want to have a look at socat man page for additional options, especially for TCP-LISTEN.

| improve this answer | |
  • socat work but for one request only, I tested it on apache2(server2) and when the page open socat close and I need to run it again. how I can apply socat to forward traffic permanently ? – tlf05649 Oct 5 at 15:11
  • As I mentioned - have a look at socat man page. I think you are looking for fork option from CHILD option group but you'll have to doublecheck on this. – Tomek Oct 5 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.