0

Suppose there is some server running on remotehost.some.where:4444. I have a software that insists to connect to localhost:5555. I can forward this with ssh as

ssh -L 5555:remotehost.some.where:4444 myuser@localhost

But this requires an unnecessary ssh connection to localhost, which the addition of -N would not prevent. How can I do this port forwarding without the login, possibly with another tool?

2

The easiest solution is to run some sort of TCP proxy. You can use socat, for example:

socat tcp-listen:5555,bind=127.0.0.1,fork tcp:remotehost.some.where:4444

While this is running, connections to port 5555 on your local host will be forwarded to port 4444 on remotehost.some.where.

The command I'm using here only listens on 127.0.0.1. If you actually want to accept connections from other hosts on port 5555, you can drop the bind=127.0.0.1 option.

| improve this answer | |
-1

There are a couple of ways of doing that.

1) If you're GNU/Linux, just use iptables to do so;

2) If you really, really, REALLY wanna use SSH, generate a RSA keypair, copy it to your ~./ssh/authorized_keys file and repeat your command, adding the -N option.

3) If you're using a Debian, or Debian-based distribution, you can use redir.

4) You can accomplish that also using socat, like this:

socat TCP4-LISTEN:80,fork TCP4:www.yourdomain.org:8080

Hope that helps.

| improve this answer | |
  • (1) not so useful without an example (and performing nat when localhost is involved can be tricky), (2) the OP explicitly doesn't want to use ssh, (3) sure, (4) that's what I said. – larsks Jan 7 at 13:35
  • 1) There are plenty examples on the Internet; 2) The OP didn't said that; 4) I've finished my answer without seeing yours. After I saw it, I upvoted your answer. – Stefano Martins Jan 7 at 13:38

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.