How To Change The Hosts File On Your Mac Computer

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 is If you add a new record to the hosts file with the following content:

and visit, it will load contents from instead of I often use this method to define a new domain name for XAMPP, instead of using 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.

Open Terminal in Mac with Spotlight

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.

nano text editor in Mac

  • 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,

Add new entry - the hosts file Mac

  • 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.

sudo killall command in Mac

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.

Leave a Reply