Change a hosts file on a Mac

We often get asked this question a lot as in many cases. With the information in this article, we will outline how to map a domain name to the local hosts file, thus overriding temporarily the DNS record for a domain.

Here are the steps to change the hosts file on a Mac:

  1. Open the Terminal app.
  2. Use the following command to open the hosts file in a text editor:
sudo nano /private/etc/hosts
  1. Enter your password when prompted.
  2. Make the desired changes to the hosts file. For example, to add an IP to a website, add the following line to the file:
192.168.0.1 example.com

Note: Replace “192.168.0.1” with your new IP address and “example.com” with the actual domain name of the website you want to add.

  1. Save the changes to the file by pressing Ctrl + X, then Y, and finally Enter.
  2. Close the Terminal app.
  3. Flush the DNS cache to ensure that the changes take effect. You can do this by using the following command in the Terminal app:
dscacheutil -flushcache;sudo killall -HUP mDNSResponder

Your Mac’s hosts file is now updated, and the changes should take effect immediately.

Leave a Comment