0

I have an SSH tunnel defined in /etc/ssh/ssh_config. It contains:

LocalForward 0.0.0.0:8000 some-service:80
LocalForward 0.0.0.0:8001 some-other-service:80

I would still like to be able to access the tunnels via their original DNS names (e.g. curl some-service should still work, rather than having to use curl 0.0.0.0:8000)

In an attempt to do this I added the following to my /etc/hosts file:

127.0.0.2 some-service
127.0.0.3 some-other-service

Now, I think, I need some iptables commands which will do the following:

When I see a request to 127.0.0.2:80 I should proxy it to 127.0.0.1:8000
When I see a request to 127.0.0.3:80 I should proxy it to 127.0.0.0:8001

Such that, curl some-service would resolve to 127.0.0.2 (via /etc/hosts, which would in turn be proxied to 127.0.0.1:8000 (via iptables), which in turn hit some-service:80 (via the ssh tunnel)


Question: I feel like there should be an easier way to achieve this? If not, what would the iptables commands look like?

  • Please delete this, otherwise a moderator will likely remove it since it's already been flagged 10x as a duplicate. Since StackExchange sites are answer sites, double-posting creates clutter, among other things. – JW0914 Sep 9 at 13:49
0

Use the ssh DynamicForward option to set up a socks proxy, by adding this to your .ssh/config:

DynamicForward localhost:8000

Then tell curl to use SOCKS:

curl --socks5 localhost:8000 ...

There are other ways to make curl use SOCKS; refer to the documentation.

  • Hey, might be missing something - not sure how that helps? – Richard Walton Sep 5 at 22:29
0

Not sure the correct etiquette here (close the question? mark as duplicate?) but I have an accepted answer for this question here:

https://serverfault.com/questions/982063/transparent-ssh-tunneling

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.