1

After connecting with an ssh host for the first time, you're prompted to add the host to the trusted known_hosts file, and are given the IP.

Warning: Permanently added the RSA host key for IP address <IP> to the list of known hosts.

I have a hint from this answer that I can retrieve some non-readable encoded information with:

ssh-keygen -H -F <example.com>

So given the hostname and that I have saved the IP in this manner, how can I retrieve that IP?

1 Answer 1

1

Not sure if I understood your question.

If it is resolve IP for given hostname then you just make a host <fqdn of server>. The host command resolves forward and reverse queries so you can also do a host <IP of interest> and you will get a FQDN hostname as answer. You could use nslookup, dig and even ping (just to mention some other) but host is my personal fav as it gives minimum information of the connection between IP and server name.

Be aware that using ping <FQDN> could be resolved different than host (which makes a DNS query) and ssh and ping will (on most default network setups) go to the hosts file first.

That means - if you have an entry in /etc/hosts which points 192.168.1.100 to some.server.com, ssh some.server.com will try to connect to this IP and not the one you would get from DNS (in case they differ).

Another thing to be aware of, the host IP does not have to match the host FQDN, eg. I use a hosting service and when I do host FQDN and then use the IP from the answer in host IP - I will NOT get my FQDN - instead I will get the FQDN of the hosting server (as my FQDN is an alias for the hosting server).

And to make this even a little bit more confusing :) If I ping www.google.com I get a 159.... IP, and with dig www.google.com I get 15 IPs all starting with 212. This just that you be aware that the name to IP resolving depends firstly of the command/application being used and then some OS networking setup and more...

6
  • So the main problem is that DNS is down for a lot of sites right now, in particular github, so I can't use nslookup etc. But I have checkhostip yes enabled so if I could retrieve that value, then I should be able to connect directly by IP or creating the entry in my /etc/hosts file. Commented Oct 21, 2016 at 19:18
  • if you make a grep <hostnam> ~/.ssh/known_hosts you will also be able to retrieve the IP for the hostname and you could try to ssh to the IP instead of the hostname if it is only a DNS problem.
    – Zina
    Commented Oct 21, 2016 at 19:22
  • My ssh config has hashknownhosts yes so my known_hosts file is not readable. grep will not work. Commented Oct 21, 2016 at 19:23
  • 1
    Oh. Now I get it. No IPs in your known hosts file because of the store hashed setting. Hm, you could try some DNS queries to other servers which might have the IP in cache. Maybe the OpenDNS ones?
    – Zina
    Commented Oct 21, 2016 at 19:27
  • Killer idea! It worked, I was able to grab a valid IP from whatismyipaddress.com/hostname-ip thanks! Commented Oct 21, 2016 at 19:30

You must log in to answer this question.

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