Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use ssh to log into remote servers, and I have a ProxyCommand setup in ~/.ssh/config to use a proxy (setup through PuTTY to connect to a VPN). The ProxyCommand uses nc to connect through the proxy (as described in the answer to How can I use SSH with a SOCKS 5 proxy?), but nc doesn't seem to be able to resolve the hostname to an IP through /etc/hosts before sending it on to the proxy, and the proxy doesn't know how to resolve the hostname.

For instance:

$ cat /etc/hosts       localhost     hostname1     hostname2

$ cat ~/.ssh/config
ProxyCommand /usr/bin/nc -x %h %p

Note that port 7777 is configured as a dynamic port in PuTTY.

$ cat /etc/resolv.conf
lookup  file bind

$ cat /etc/nsswitch.conf
hosts:  files dns

If I use ssh user@ then the connection succeeds, but if I use ssh user@hostname1 then hostname1 gets passed to the proxy instead of being resolved to and the connection fails. Does anyone know of any configurations that need to be made to make netcat hostname resolution through /etc/hosts work in cygwin?


share|improve this question
does anything need to be executed to load the changes I made to the configuration files? – Rusty Lemur Oct 24 '12 at 19:55

is /etc/hosts correctly delimited with whatever line ending is required (CR or CRNL)?

does nc neglect/etc/hosts and look at %windir%\system32\drivers\etc\hosts by any chance?

share|improve this answer
Can you expand your answer? This site is also for non-professionals, and we discourage small, short answers – Canadian Luke Oct 24 '12 at 21:13
I believe /etc/hosts is correctly delimited with the UNIX line feed only (no carriage return). And I copied the file from the Windows location to Cygwin's /etc/hosts. After copying it I ran sed -i 's/\r//g' to remove any instances of carriage returns. – Rusty Lemur Oct 24 '12 at 21:58

What is happenning there is that you're using the ssh_config %h substitution, but according to the manual, this doesn't mean that the substituted value will also be preprocessed in any way.

But, because the command is being passed through a shell, you can use a subshell to run a command that will do a name resolution, something like this:

ProxyCommand /usr/bin/nc -x $(perl -MSocket -le 'print inet_ntoa inet_aton shift' %h) %p

Specific command courtesy of

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .