Can /etc/hosts config reverse resolution?

小武哥 picture 小武哥 · Nov 13, 2012 · Viewed 31.5k times · Source

As we all known, we can add 'ip host' item in /etc/hosts to mock a DNS's name resolution, now comes the question, can I use /etc/hosts to do inverse resolution, form ip to hostname? Or is there any other handy way to do this? Thanks!

Answer

Tor Magnus picture Tor Magnus · Oct 25, 2013

Maybe. It will depend on the tool you use to do the lookup and the configuration of resolving on your computer.

For example gethostbyaddr() will check /etc/hosts if "files" is in the hosts section of your /etc/nsswitch.conf

Note however that not all tools will do a local resolve, such as the "host" command for example, so it depends entirely on how you are attempting to do the lookup.