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?
- 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.
- Click the Finder icon at the left bottom of the macOS desktop Dock.
- Click Go —> Go to Folder… menu item on the macOS top menu bar.
- Input /private in the Go to the folder: popup dialog input text box. Then click the Go button to .
- Then click folder etc, under the folder etc, you can find the file hosts.
2. How To Modify hosts Content In MacOS?
- 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 ﬁle unchanged and work with a copy, click Duplicate. Duplicate Cancel Unlock
- You can click the Unlock button to unlock it, or you can follow the below method to make it editable.
- Right-click the hosts file, click the Get Info menu item in the popup menu list.
- 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.
- 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.
- Click the Finder icon in the desktop dock. Then click Go —> Applications —> Utilities —> Terminal in top menu to open a terminal.
- 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.
- After opening the terminal, input the command
cd /private/etcto go to hosts file saved folder.
- Then execute the command
su nano hoststo edit it, during that process, it may ask you to provide an administrator password, just input the password and go on.
- After input correct IP domain mappings, save the hosts file and exit it.
- In the terminal, execute the command
sudo killall -HUP mDNSResponderto flush the DNS cache in macOS to make the new configuration take effect.
- Above is just the steps to change the hosts configuration file in macOS.