How To Modify Hosts File In Mac

When you use macOS, sometimes you may need to modify IP domain mappings in the hosts file. This article will tell you where the hosts file is saved and how to modify it in macOS.

1.Where Is The hosts File Saved In macOS?

  1. Because the macOS is a UNIX system, so you can find the hosts file in /private/etc/hosts. Follow the below steps to open it.
  2. Click the Finder icon at the left bottom of the macOS desktop Dock.
  3. Click Go —> Go to Folder… menu item on the macOS top menu bar.
  4. Input /private in the Go to the folder: popup dialog input text box. Then click the Go button to .
  5. Then click folder etc, under the folder etc, you can find the file hosts.

2. How To Modify hosts Content In MacOS?

  1. Right-click hosts file, open it with a text editor. When you input new IP domain mappings, it will show you that the file is locked as below.
    The file "hosts" is locked.
    If you want to make changes to this document, click Unlock. 
    To keep the file unchanged and work with a copy, click Duplicate.
          Duplicate         Cancel          Unlock
  2. You can click the Unlock button to unlock it, or you can follow the below method to make it editable.
  3. Right-click the hosts file, click the Get Info menu item in the popup menu list.
  4. In the popup file info window, expand Sharing & Permissions section, click the lock icon at the bottom right corner to unlock it, and change permissions from Read Only to Read & Write for selected users or groups.
  5. Click the lock icon to lock permissions again. Now you can edit the hosts file as you want.

3. Modify hosts Content With Command-Line.

  1. Click the Finder icon in the desktop dock. Then click Go —> Applications —> Utilities —> Terminal in top menu to open a terminal.
  2. You can also click the Launchpad app just behind the Finder app in the desktop dock and search terminal in the search box to open it.
  3. After opening the terminal, input the command cd /private/etc to go to hosts file saved folder.
  4. Then execute the command su nano hosts to edit it, during that process, it may ask you to provide an administrator password, just input the password and go on.
  5. After input correct IP domain mappings, save the hosts file and exit it.
  6. In the terminal, execute the command sudo killall -HUP mDNSResponder to flush the DNS cache in macOS to make the new configuration take effect.
  7. Above is just the steps to change the hosts configuration file in macOS.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.