How To Modify Hosts File In Mac

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

1.Where The hosts File Is Saved In MacOS?

Because MacOS is a unix system, so you can find hosts file in /private/etc/hosts. Follow below steps to open it.

  1. Click Finder icon in the left bottom of the desktop Dock.
    mac finder command icon new
  2. Click Go —> Go to Folder menu item.
    mac finder go to folder
  3. Input /private in the input box. Then click Go button.
    input folder in go to folder dialog
  4. Then click folder etc, under the etc folder you can find hosts file.
    mac os hosts file

2. How To Modify hosts Content In MacOS?

  1. Right click hosts file, open it with text editor. When you input new ip domain mappings, it will show you that the file is locked as below.
    hosts file is locked dialog
  2. You can click Unlock button to unlock it, or you can follow below method to make it editable.
  3. Right click the hosts file, click 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 bottom right corner to unlock it and change permissions from Read Only to Read & Write for selected user or groups.
    change hosts file permissions in macos
  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 Finder icon in desktop dock. Then click Go —> Applications —> Utilities —> Terminal¬†in top menu to open a terminal.
    open mac os terminal in applications
  2. You can also click Launchpad app just behind Finder app in desktop dock and search terminal in the search box to open it.
  3. After open terminal, input cd /private/etc in it to go to hosts file folder.
  4. Then execute su nano hosts command to edit it, during that process, so may ask you to provide administrator password, just input the password and go on.
  5. After input correct ip domain mappings save hosts file and exit.
  6. In terminal, execute command sudo killall -HUP mDNSResponder to flush DNS cache in MacOS to make the new configuration take effect.
READ :   How To Install Tomcat In MacOS

Above is just the steps to change hosts configuration in MacOS.

(Visited 61 times, 1 visits today)

Leave a Reply

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.