Do you know what the hosts file is? Have you ever modified the hosts file on your Windows PC?
I’m sure that you have heard about this file many times before. So, what is it?
It is a system file of Windows that used to map hostnames to IP (stands for Internet Protocol) addresses. This system file assists in addressing network nodes in your computer network.
It is a standard part of the operating system’s IP implementation and helps to translate human-friendly hostnames into IP addresses, a numeric protocol, which using to identify and locate a hostname in an IP network.
In some points, the hosts file works like the Domain Name System (DNS). However, it is under the direct control of you, on your computer. For example, the IP address of usefulmacguide.com is 220.127.116.11. If you add a new record to the hosts file with the following content:
and visit usefulmacguide.com, it will load contents from 18.104.22.168 instead of 22.214.171.124. I often use this method to define a new domain name for XAMPP, instead of using 127.0.0.1 to browse the localhost. If you don’t know what XAMPP is, visit here to read more.
That is a simple example to describe how does “the hosts file” work. Modifying this file in Windows operating system is quite easy as it is stored in “C:\Windows\System32\drivers\etc”.
But did you know how to change the hosts file in Mac OS? Apparently, it will not store in the same location as I mentioned above.
How To Change Mac Hosts File?
In Windows, you can easily go to the folder that contains the hosts file and then change its contents. It is the fastest method.
However, in Mac OS, the best method to work with the hosts file is to use Terminal application. To open this app, press Command + Space and then type: Terminal, and press Enter.
After that, following the instruction below to add a new entry to the hosts file or remove an entry from it.
- Type: sudo nano /etc/hosts and then press Enter (or Return).
- Enter your administrator password. This is the password that you use to log into your Mac computer.
- The nano text editor will be opened. From here, you can add a new line or remove the current one, depending on what you want to do. The structure of a line should be: IP-address + [space] + domain-name. For example, 127.0.0.1 www.google.com.
- After you have modified the hosts file, press Control + O to save the file.
- Press Contrl + X to exit the nano text editor.
- You will be back to Terminal window, type: sudo killall -HUP mDNSResponder and press Enter.
This command will help to flush all DNS cache on your Mac computer. By that, it does not get confused by any changes you have made to the hosts file.
After reading this guide, I will know how where the hosts file stored in, as well as how to changes its contents.
If you have any questions about this file or anything related to Mac OS, I will be glad to help you out. Just leave your comment below.