whatsmydns.net - DNS Propagation Checker
  1. What's My DNS?
  2. Hosts File

Hosts File

The hosts file is a file located on your computer that is used as the first step in the DNS lookup process for DNS hostname resolution.

A common use for making changes to this file is to test changes to DNS records before making them live on the Internet as well as setting up custom hostnames for local testing and development.

Where is the hosts file located?

The most common question that many people have around the host file is how do you find it? What is the path and location of the hosts file?

The path of the hosts file varies depending on the operating system that you're using.

Windows host file location

The hosts file for Windows is located in C:\Windows\System32\Drivers\etc\hosts.

In order to edit this file, you will need to do so as the local system administrator. This can be done by right clicking on the shortcut to your favorite text editor (which can be as simple as Notepad) and choosing the "Run as administrator" option.

Linux host file location

The hosts file for Unix, Linux and other Unix like operating systems is located in /etc/hosts

Apple MacOS host file location

The hosts file for MacOS is located in /etc/hosts as MacOS is a Unix based system and follows many of the common file location conventions.

How do you edit your hosts file?

Once you’ve found the location of your hosts file for your specific operating system, all you need to edit it is a simple text editor. You can use Windows Notepad, TextEdit on the Mac, as well as command line text editors like vim or nano on Unix based systems.

You will need to make sure that when you’re editing this file that you do so with an account which has administrator privileges as this is a protected system file.

Hosts file format

Once you have located the hosts file, the format is very simple. On a new blank line you need to enter the desired IP address followed by a space (or tab) and then the hostname you would like to assign to this. You can add additional hostnames departed by spaces (or tabs) as well.

This process will create a local DNS A record on your system.

For example: example.com

or multiple hostnames at once: example.com www.example.com mysite.com

Adding comments to your hosts file

It can sometimes be useful to add comments to your hosts file, especially if you have many entries or entries that you switch between from time to time.

To add a comment, you simply need to use the # character, and anything after this will be ignored.

For example:

# this entire line is a comment example.com # this text at the end of a host file entry is a comment
# example.com this entire line a comment and not a valid hosts file entry