How to: Edit your computer's local hosts file in macOS or Windows


Introduction

macOS

Open Terminal and type sudo nano /etc/hosts. Then, press the return key. Type the password of the current administrator account. Edit the file as desired.

Windows

Open Notepad as an administrator. Open the C:\Windows\System32\drivers\etc\hosts file, and edit as desired.

Instructions

Jump to:

A: macOS

A1) Open the Terminal app.

A2) In the Terminal window, type sudo nano /etc/hosts and press the return key on your keyboard:

example screenshot

A3) Type the password of the current administrator account on your Mac. Then, press return.

NOTE: The Terminal window will not display any indication that you are typing your password. Simply type your password as normal and press return.

example screenshot

A4) Make any necessary changes, and then press control+O on your keyboard to save the file.

TIP: You can navigate up, down, left, and right by using the arrow keys on your Mac's keyboard.

example screenshot

A5) At the bottom of the Terminal window, Terminal will ask you to confirm the file name to which to save the changes. Simply press return without making any changes to the default file name (/etc/hosts).

example screenshot

A6) You should see a confirmation at the bottom of Terminal that it wrote a certain number of lines of text to the file. Now, press control+X on your keyboard to exit the hosts file.

example screenshot

A7) In the Terminal window, type sudo killall -HUP mDNSResponder and press return.

example screenshot

B: Windows 11

B1) Click your Start button.

example screenshot

B2) Type Notepad into the search field, but do not press Enter.

example screenshot

B3) In the search results, right-click on Notepad and choose Run as administrator.

example screenshot

B4) If prompted by User Account Control, click Yes.

example screenshot

B5) Click File and choose Open.

example screenshot

B6) Navigate to C:\Windows\System32\drivers\etc. On the bottom right-hand corner, use the drop-down option to show All files.

example screenshot

B7) Open the hosts file.

example screenshot

B8) Make any necessary changes.

NOTE: Entries that begin with the pound sign (#) are for comments or examples. They act as if they are not there. For entries to work, do not use the pound sign (#).

example screenshot

B9) Click File and choose Save.

example screenshot

C: Windows 10

C1) Click your Start button.

C2) Type Notepad into the search field, but do not press Enter.

example screenshot

C3) In the search results, right-click on Notepad and choose Run as administrator.

example screenshot

C4) If prompted by User Account Control, click Yes.

example screenshot

C5) Click File and choose Open.

example screenshot

C6) Navigate to C:\Windows\System32\drivers\etc and open the hosts file.

TIP: Notepad might default to displaying .txt files only. Use the drop-down option on the bottom right to show All Files.

example screenshot

C7) Make any necessary changes.

NOTE: Entries that begin with the pound sign (#) are for comments or examples. They act as if they are not there. For entries to work, do not use the pound sign (#).

C8) Click File and choose Save.

example screenshot


OUTCOME

You have made any desired changes to the hosts file on your computer.