What a hosts file can change

A hosts file is a small text file on your computer that pairs hostnames with IP addresses. It can make a name such as example.com point to a particular server without changing the domain’s public DNS records. Hosts entries are useful when testing a website before a DNS change, but a forgotten entry can later make the site appear broken or outdated on one computer.

This is worth checking when other people can reach a domain normally but your computer shows a different website, connects to an old server, or fails to connect. It is one possible cause, not a diagnosis: browser settings, cached data, VPNs, proxies, and network configuration can also produce differences.

Find the file and look for the exact hostname

On Windows, the hosts file is usually at C:\Windows\System32\drivers\etc\hosts. On macOS and Linux, it is usually at /etc/hosts. Open it in a text editor to inspect it; you do not need to change it yet. Editing may require administrator privileges, so take care not to save accidental changes.

Look for the hostname that is misbehaving. A typical active entry contains an IP address followed by one or more names, such as “192.0.2.10 example.com www.example.com”. The address in that example is for illustration, not a server to use. Lines beginning with # are comments and do not create a mapping. An entry for example.com does not automatically cover www.example.com, so check each name you actually visit. Also look for both IPv4 and IPv6 entries: a hostname could have an unexpected mapping in either format.

If you find a matching entry, note its IP address and whether it appears to be an intentional test setting. Avoid sharing the whole hosts file publicly. Although it normally does not contain passwords, it may reveal internal hostnames or network details.

Compare local resolution with a DNS lookup

Next, compare the address your computer uses with an answer from DNS. A command such as “ping example.com” can show the address your system selected, even if the server does not answer ping requests. On many Linux systems, “getent hosts example.com” is another way to inspect system name resolution. Replace example.com with the exact hostname you are troubleshooting, and pay attention to whether the result is IPv4 or IPv6.

For a DNS-only comparison, query the name with “nslookup example.com” or, where available, “dig example.com”. These tools generally query DNS rather than reading hosts-file mappings. If the address selected by the system matches a hosts entry but differs from the DNS answer, the entry is a strong explanation for the local difference. A matching address alone does not prove the hosts file is responsible, because DNS might return the same address.

DNS answers can legitimately vary by resolver, location, or record type. If you compare results, use the same hostname and distinguish A records from AAAA records. A browser may also use a proxy or its own name-resolution settings, so a command-line result will not always predict exactly what the browser does.

Remove an outdated override safely

Before editing, make a copy of the hosts file or record the line you plan to change. If you confirm that a matching entry is no longer needed, remove only that entry or place # at the start of its line to disable it. If the line contains several hostnames, check whether any are still needed before changing the whole line. Leave unrelated entries alone, including standard localhost entries.

Save the file with administrator privileges if required, then test the exact hostname again. You may need to restart the browser or clear a local name-resolution cache before the change is reflected. If an override reappears, ask whoever manages the computer or its configuration whether a development tool, security product, or organization policy is maintaining it. Do not repeatedly delete an entry whose purpose you have not established.

Finally, check both the bare domain and any subdomain you use, such as www or mail. A hosts-file fix affects only the computer where you made it; it does not update public DNS. If the problem persists after you rule out local overrides, continue troubleshooting the relevant DNS records, browser settings, and network connection.

Back to category ↗