How To Find and Edit Your Mac Hosts File (in 4 Steps)

The hosts file on your Mac acts like a local phonebook for websites. It tells your computer the IP address for specific domain names (like [invalid URL removed]). You can edit this file to override the default DNS settings and point websites to different IP addresses. Here’s how to find and edit your Mac hosts file in 4 steps:

1. Open the Terminal Application:

  • Launch the Terminal application, which is found in the Utilities folder within Finder. You can also use Spotlight search (Command + Spacebar) and type “Terminal” to open it quickly.

2. Access the Hosts File:

  • In the Terminal window, type the following command to access the hosts file:
sudo nano /etc/hosts
  • Press Enter. You’ll be prompted for your administrator password. Type your password and press Enter again (note that characters won’t be shown while typing your password for security).

3. Edit the Hosts File (Optional):

  • The hosts file will open in the Nano text editor. Lines with a # symbol are comments and ignored. You can add new entries by following this format:
IP_Address Domain_Name [alias_name]
  • Replace IP_Address with the actual IP address you want to direct the domain name to. Replace Domain_Name with the website address (e.g., [invalid URL removed]). The alias_name (optional) is another name you can use for the website.

4. Save and Exit (Optional):

  • If you made edits, press Control + O to save the changes. When prompted for the filename, press Enter to confirm.
  • To exit the Nano editor, press Control + X.

Flush the DNS Cache (Recommended):

  • After editing the hosts file, it’s recommended to flush your Mac’s DNS cache so it can pick up the changes. Open Terminal again and type the following command:
sudo dscacheutil -flushcache
  • Press Enter and type your administrator password when prompted.

Remember: Editing the hosts file can affect how certain websites load on your Mac. Make sure you understand what you’re doing before making any changes. Always back up your hosts file before editing it in case you need to revert to the original settings.