How to use the “hosts” file?
file is used to map hostnames (in other words domains) to IP addresses. With the hosts
file you can change the IP address that you resolve a given domain name to. This change only affects your own computer without affecting how the domain is resolved worldwide.
This is particularly useful when you wish to see how a website will look like when hosted on a different server without making any DNS changes to your domain.
The location of the hosts
file, depending on the operating system that you are using, is:
- Windows -
SystemRoot > system32 > drivers > etc >
By default the system root is
C:\Windows, so if you are using Windows, your
hosts file is most probably: C:\Windows\System32\drivers\etc\
- Linux -
- Mac OS X -
Let's say that you wish to resolve yourdomain.com
to the IP address 188.8.131.52
. In this case you would need to open up the hosts file with a text editor and append the following line:
(Note: Make sure that you don't have any
|1||184.108.40.206 yourdomain.com www.yourdomain.com|
# signs in front of the IP address as they will deactivate this entry)
This will "tell" your computer to resolve yourdomain.com to 220.127.116.11. Once you do that you may need to clear your web browser's cache, afterwards, if you try to reach your domain http://yourdomain.com
in a browser it should take you to the site hosted on the server with IP 18.104.22.168.
More detailed instructions on how to locate and edit the hosts file on different operating systems are available below:
Windows 8 and 10
- Press the Windows key (previously Start menu).
- Use the Search option and search for
Notepad and select
Run as administrator.
Notepad, open the hosts file at:
- Add the line and save your changes.
- Open up the
- Use the
nano command line text editor, or a different one you have available to open up the
hosts file. The command with nano is as follows (the command will require your Linux user's password):
- Add the appropriate changes in the hosts file.
- Use the
X key combination to save the changes
Mac OS X 10.6 through 10.12
You should be logged in with a user with administrator privileges on your MAC.
- Edit the
hosts file with a command line text editor such as
nano by typing the following line in the terminal (the command will require your Mac user's password):
|1||sudo nano /private/etc/hosts|
- Add your changes at the bottom of the file.
- Save the changes with the
X key combination.