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

LocalForward some-service:80
LocalForward 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

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

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

When I see a request to I should proxy it to
When I see a request to I should proxy it to

Such that, curl some-service would resolve to (via /etc/hosts, which would in turn be proxied to (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

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

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


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.