Sample Header Ad - 728x90

How do `/etc/hosts` and DNS work together to resolve hostnames to IP addresses?

22 votes
3 answers
51736 views
In Linux, how do /etc/hosts and DNS work together to resolve hostnames to IP addresses? 1. if a hostname can be resolved in /etc/hosts, does DNS apply after /etc/hosts to resolve the hostname or treat the resolved IP address by /etc/hosts as a "hostname" to resolve recursively? 2. In my browser (firefox and google chrome), when I add to /etc/hosts: 127.0.0.1 google.com www.google.com typing www.google.com into the address bar of the browsers and hitting entering won't connect to the website. After I remove that line from /etc/hosts, I can connect to the website. Does it mean that /etc/hosts overrides DNS for resolving hostnames? After I re-add the line to /etc/hosts, I can still connect to the website, even after refreshing the webpage. Why doesn't /etc/hosts apply again, so that I can't connect to the website? Thanks.
Asked by Tim (106430 rep)
Feb 10, 2019, 04:15 PM
Last activity: Sep 15, 2022, 10:45 AM