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
- Start out by opening a Terminal. To do so, open your Applications folder, select the Utilities folder, and then double-click Terminal.
- At the Terminal prompt, enter the following line:
sudo nano /etc/hosts
and then hit return. Enter your password when prompted.
- 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.
- 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
- 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.
- 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.
- Enter /etc in the space provided and then click the Go button.
- 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
- BBEdit will now open and load up the hosts file.
- 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.
- After you’ve made your changes, select File and then Save
- You’ll be asked to enter your password – do so.
- 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.
b