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.
- Click Finder icon in the left bottom of the desktop Dock.
- Click Go —> Go to Folder menu item.
- Input /private in the input box. Then click Go button.
- Then click folder etc, under the etc folder you can find hosts file.
2. How To Modify hosts Content In MacOS?
- 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.
- You can click Unlock button to unlock it, or you can follow below method to make it editable.
- Right click the hosts file, click Get Info menu item in the popup menu list.
- 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.
- 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 Finder icon in desktop dock. Then click Go —> Applications —> Utilities —> Terminal in top menu to open a terminal.
- You can also click Launchpad app just behind Finder app in desktop dock and search terminal in the search box to open it.
- After open terminal, input
cd /private/etcin it to go to hosts file folder.
- Then execute
su nano hostscommand to edit it, during that process, so may ask you to provide administrator password, just input the password and go on.
- After input correct ip domain mappings save hosts file and exit.
- In terminal, execute command
sudo killall -HUP mDNSResponderto flush DNS cache in MacOS to make the new configuration take effect.
Above is just the steps to change hosts configuration in MacOS.