I'm trying to create a setup where I can connect to some service running on a host only reachable through a SOCKS proxy by the host's actual name and the port the service actually uses (so that application trying to use that service work without changes). To do this, I'm following these steps:

  • Open a SOCKS tunnel using an SSH connection to some intermediate host, which has access to the host running the service.
  • Assign some unused IPv6 address (e.g. fc00::1) to the loopback device.
  • Use socat to open the port used by the service I want to reach on that address and forward connection requests to the SOCKS proxy.
  • Add an entry to /etc/hosts for the host I want to reach and the address assigned to the loopback device.

I'm planning to automate all these steps. This works great, except for one problem; a lot of services running on my local machine use the same ports I want to reach on the remote hosts (e.g. SSH, HTTP …) and at least by default they listen on all interfaces (i.e. use the "any" address This prevents any other process from opening the same port, even on just a specific address. Some services, I can reconfigure to only listen on the original loopback addresses (, but for some services, like SSH, it doesn't make sense and for some user-land applications I use, I can't event control which ports thy open using which addresses.

One conceivable solution would be if it was possible to mark an interface (I could create a second loopback device) or an address to not be used by processes that specify the "any" address when opening a listening socket.

Is that even possible or is there some other way to work around this problem?

Your Answer

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

Browse other questions tagged or ask your own question.