2

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 Answers 2

8

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.

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.

2
  • (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. Commented Jan 7, 2020 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. Commented Jan 7, 2020 at 13:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.