How to Find and Edit Your Hosts File on MacOS (in 4 Steps)

| 2 min read
Last updated on
systemmac

Find hosts file

Location of the hosts file on MacOS: /etc/hosts

How to edit the hosts file on MacOS

1. Open Terminal

  • Press Cmd + Space to open “Spotlight Search”
  • Type in “Terminal” and press Enter

2. Open /etc/hosts in a text editor

In the terminal run

sudo nano /etc/hosts

or

sudo vim /etc/hosts

On my machine the initial hosts file was:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

3. Modify the hosts file as needed

In example, to map your-domain.com to your localhost the modified hosts file could look simething like:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1 your-domain.com

4. Clear DNS Cache on your MacOS to apply the changes

Depending on the version of MacOS that you have you could run one of the following commands in the Terminal:

sudo killall -HUP mDNSResponder

or

sudo discoveryutil udnsflushcaches

or

sudo dscacheutil -flushcache

or

sudo lookupd -flushcache

Thank you for reading!

Liked this post?
Buy me a coffee