Two Easy Ways to Edit the macOS hosts File

This tutorial will show you two different methods you can use to edit the “hosts” file in macOS.

Background

Editing the hosts file can have fairly adverse effects to your Internet and network connections if you’re not sure what you’re doing. Please be careful and double-check any changes you make.

The methods used to edit a hosts file on a Mac have changed over the years. We’ll go over two different methods to that should work no matter which version of macOS or OS X you’re running – by using the Terminal or if you’re not entirely comfortable using the Terminal, using the (free) text editor BBEdit.

Using the Terminal to Edit a hosts File

  1. Start out by opening a Terminal. To do so, open your Applications folder, select the Utilities folder, and then double-click Terminal.
  2. a Finder window with an arrow pointing at the Terminal app

  3. At the Terminal prompt, enter the following line:

    sudo nano /etc/hosts

    and then hit return. Enter your password when prompted.

  4. entering a command to edit the hosts file in a Terminal for macOS

  5. Your hosts file will now open in the text editor “nano”. From here you can make any changes you deem fit/need. Since this is a Terminal you won’t be able to use your mouse/trackpad to move the cursor around, so use the arrow keys instead. When you’re done making any changes, enter the keyboard combo: ctrl + x and then when you’re asked if you’d like to save the changes, type the letter y and then hit return again.
  6. a Terminal window with the contents of a hosts file being displayed

  7. That’s it – you’re done, although you may want to clear your DNS cache so any changes you just made take effect right away. Should you ever need to re-edit your hosts file, follow the instructions from the beginning.

Using BBEdit to Edit a hosts File

  1. If you’re not comfortable using the Terminal to edit a system file that’s not a problem. You can use the fantastic (and free) editor BBEdit. It’s super easy to install – just open the DMG file and then drag BBEdit to your Applications folder.
  2. Once you’ve got BBEdit installed, open a Finder window and then select Go from the Menu Bar and Go to Folder… from the list of options.
  3. the Go menu in Finder with an arrow pointing at Go to Folder

  4. Enter /etc in the space provided and then click the Go button.
  5. the dialogue box to enter a location to go to in the macOS Finder

  6. Scroll through the list of files in your /etc folder until you find the hosts file. Right-click the file (or hold down the ctrl key and then click the file) and select Open With then BBEdit
  7. the context menu displayed on the hosts file to edit with BBEdit in macOS

  8. BBEdit will now open and load up the hosts file.
  9. edit the hosts file in macOS with BBEdit

  10. As soon as you make a change, a window will pop up and ask you if you want to unlock the hosts file. You do, so click the Unlock button.
  11. b
    the BBEdit Permission Window

  12. After you’ve made your changes, select File and then Save
  13. the BBEdit File menu with an arrow pointing at the Save option

  14. You’ll be asked to enter your password – do so.
  15. the macOS enter your password window

  16. That’s it – you’re done, although you may want to clear your DNS cache so any changes you just made take effect right away. Should you ever need to re-edit your hosts file, follow these instructions from the beginning.

If this article helped you, I'd be grateful if you could share it on your preferred social network - it helps me a lot. If you're feeling particularly generous, you could buy me a coffee and I'd be super grateful :)

buy a coffee for simplehelp.net


Home » Mac » Two Easy Ways to Edit the macOS hosts File

Leave a Comment

Your email address will not be published.