3

Our accounts in our lab are all mounted over NFS and are accessible over all the systems in a subnet. So, effectively we can ssh into any of the machines in the subnet and continue our work. The problem is that the machines come up or go down randomly because of people accidently turning it off etc. To find running machines I scan the subnet using nmap and choose a machine.

Because of the above problem, I can't put a fixed entry for Hostname in my ssh config entry. So, how can I have an ssh config entry that will have all other parameters except Hostname such that the ssh config entry and the Hostname can somehow be given together while running ssh?

3

The Host directive can take multiple hosts, for example:

Host *.domain.tld specific-host.tld 10.*.*.*
User foo
Port 2222

This would set user and port for all hosts matching the star pattern, the explicit host specific-host.tld, or, assuming you type IP numbers, any host whose first IPv4 byte is 10. Then you can add Host / HostName pairs to give nicknames to specific hosts, for example.

8
  • But that's the problem. There are over 100 machines in that subnet, and at any point of time you can never say with confidence which ones will be up. In this case I would have to make over 100 Host/Hostname entries. I'm looking for a much more efficient way.
    – Hashken
    Apr 14 '15 at 20:08
  • @Hashken: Is there any pattern to the names? What settings do you want for each?
    – dhag
    Apr 14 '15 at 20:09
  • The settings for now just include Username, Port, IdentityFile, DynamicForward. They are all part of the 10.a.b.0 subnet. They don't have any common domain names.
    – Hashken
    Apr 14 '15 at 20:12
  • If there's no pattern to the names, and you would like to connect using DNS names rather than IP numbers, then I can't think of a solution. If you are willing to connect by IP number, then you could write 'Host 10.*.*.*' to match the relevant addresses.
    – dhag
    Apr 14 '15 at 20:18
  • I want to connect only via IP addresses. But won't giving the Hostname as 10.a.b.* make ssh try to connect to all hosts in the network? Will it stop after establishing one connection? Also, won't ssh take too long to figure out for each host if it's down or not?
    – Hashken
    Apr 14 '15 at 20:19
0

I had a similar problem and wrote a wrapper around SSH to verify if the host was up or not using nc -

https://github.com/cws-khuntly/dotfiles/blob/master/functions.d/F09-network

Have a look at validateServerAvailability.

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.