Skip to content
hostcomplex

The Hosts File

Maarten Soetens 3 min read

What the Hosts File Does

The hosts file is a plain-text file on a computer that maps host names to IP addresses. Each line pairs an address with one or more names, so the device can resolve those names locally without asking DNS. Most desktop operating systems have one. On Windows it sits in the system folder, while on Linux and macOS it is at /etc/hosts.

A line such as 203.0.113.10 example.com tells the device that example.com is at that address. The address shown belongs to a range reserved for documentation, so it is safe to use as an example.

How the Hosts File Overrides DNS

Most operating systems check the hosts file before they send a query to DNS. If a name is listed there, the listed address is used and no DNS lookup takes place for that name. For the full sequence, see how DNS works. The order can be changed on most systems, but the default favors the local file.

This has two practical effects. The override applies only to that one device, not to other computers or phones on the same network. It also ignores TTL entirely, because an entry stays in place until someone removes it. Normal DNS and its caches are not consulted for that name.

Using the Hosts File to Preview a Site

A common use is previewing a site before a DNS change. Suppose you have moved a website to a new server, but the domain still points to the old one. A temporary entry on your own computer can point the domain at the new server instead of the public A record. That lets you open the site as visitors will see it after the switch, without affecting anyone else. The same idea helps developers test a local build under a real domain name.

Some people also use the file to block unwanted domains by pointing them at an address where nothing responds. Keep in mind that a preview is only as accurate as the server behind it. If the new server does not yet hold a certificate for that domain, the browser will show a security warning even though the page loads.

Frequently asked questions

Does editing the hosts file change DNS for everyone?

No. The hosts file only affects the device where it is edited. Other computers, phones and the wider internet keep using DNS as usual. This is what makes it useful for testing, and also why a site can work on one device but not on another.

Is it safe to use the hosts file?

It is safe when you know what each entry does, because the file is simple and changing it requires administrator rights. Problems come from forgotten or unknown entries, which can quietly send traffic to the wrong address. Malware sometimes adds lines to the hosts file, so an unexpected entry for a well-known site is worth investigating.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.