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.
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.
The hosts file for Windows is located in
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.
The hosts file for Unix, Linux and other Unix like operating systems is located in
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.
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.
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.
or multiple hostnames at once:
127.0.0.1 example.com www.example.com mysite.com
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.
# this entire line is a comment 127.0.0.1 example.com # this text at the end of a host file entry is a comment # 127.0.0.2 example.com this entire line a comment and not a valid hosts file entry