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!
The hosts file on your computer allows you to override DNS and manually map hostnames (domains) to IP addresses. This can come in handy during migrations as you might want to see how your website looks on a different server, but perhaps the DNS hasn't propagated yet.
You can bypass DNS lookups by adding an entry to the hosts file. Where 192.0. 2.6 and www.example.com should be replaced by the new server's IP address and the hostname respectively.
order doesn't matter except to the humans reading it. Sometimes I order mine in numerical order of the IPs and sometimes I sort it alphabetically by host name. The system doesn't care. The only time order matters is if you have conflicting information in the file.
resolv. conf specifies nameservers in order of search preference. hosts overrides all nameservers by mapping urls/shortnames to IPs.
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.
Yes. It does that automatically if the application uses Name Service Switch libraries (most applications do), and if /etc/nsswitch.conf
is configured to resolve IPs from /etc/hosts
with a line such as this:
hosts: files dns
You can test the reverse name resolution with either of the options below:
getent hosts 127.0.0.1
or
resolveip 127.0.0.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With