$HOME/.ssh/config and host/hostname resolution how-to?
Darren Tucker
dtucker at zip.com.au
Thu Dec 20 07:40:01 EST 2007
Duncan Ferguson wrote:
> Hiya,
>
> What is the easiest way of looking up a hostname to see if it exists,
> taking into account the .ssh/config file?
>
> If i have an entry in my file
>
> host host1
> hostname server.domain.name
>
> then usual OS calls won't recognise the 'alias' host1. So, i need to
> make a call via ssh somehow to check if the name resolves without
> actually initiating a full blown 'expensive' connection to it, such
> as using 'ssh host1 true' or something (which also relies on 'true'
> being on the path, or always being installed in the same place if the
> path is provided - neither of which can be guaranteed).
>
> I tried ssh-keyscan, but this ignores the config file (probably
> correctly), so what is the more appropriate way to perform the name
> validation? I have tried 'ssh -n host1' which seems to work - would
> this be the best option?
I'm not quite sure what you're trying to achieve, could you give an example?
Depending on what you want, there's a couple of options.
If you just want to return quickly if the host is down, you can set the
ConnectTimeout to a lowish value.
If you want to do something more complicated, (eg fail if your
dial-on-demand link is down or similar) you could use a ProxyCommand and
implement whatever logic you want in a shell script (that finishes by
exec'ing netcat).
--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
More information about the openssh-unix-dev
mailing list