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 have an SSH server set up on a machine which, unfortunately, changes its IP address quite often due to DHCP. I've worked around it with a small script which iterates over all the addresses for a subnet and tries to connect to each machine. The downside is that it's quite slow.

Is it possible to use the ssh command line client to connect to a machine in a subnet only if the server key matches a specific one?

share|improve this question
??? Why don't you just set the server to a static IP? or connect by hostname? This is really inefficient. – caliban Sep 8 '09 at 8:47
Easy: because I can't :-) – Robert Munteanu Sep 8 '09 at 9:24
You can, it's called dynamic DNS. – grawity Sep 8 '09 at 13:17
Does dynamic DNS work for private IP ranges? – Robert Munteanu Sep 8 '09 at 15:23

Add all the possible addresses and the server's public key to ~/.ssh/known_hosts on the client. Then set the StrictHostKeyChecking option. SSH will then refuse to connect to servers that do not match the key in the known_hosts file.

share|improve this answer

The entire premise of this question seems flawed. I will try and answer the question you asked, rather than theorize what your trying to accomplish.

Obviously If this is for Private IPs, your defining something which exists on a LAN. Dynamic DNS is not for such uses, it only places a domain on an externally facing network. It's something you might want on your router, to create a 'static domain' to workaround an ISP constantly changing your public IP address.

You interestingly lack the ability to set a static IP address, which is the sanest way to deal with problems regarding changing IPs. Often a router will automatically report an A record, when it's DNS queried for specific hostname. I recommend you verify your hostname is set correctly, and connecting in said manner is not possible, before venturing further.

MDNS is your last, and likely only, option to such a problem. Remember other devices must have the ability to multicast, and use MDNS addresses. Setting this up is beyond the scope of this answer, as it's specific to each OS. Mac OS X calls this service Bonjour, It's also available for Windows and is installed with iTunes. Gnu/Linux provides MDNS via Avahi, which is often pre-installed with most recent GNU/Linux distributions.

You wanted an answer to your question, and now you got one. Please check accept, It keeps this whole shebang running.

share|improve this answer

You must log in to answer this question.

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