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


Instructions

Jump to: B: Windows 11

A: macOS

  1. Open the Terminal app.

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

    Mac Terminal open with script entered

  3. 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.

    Mac Terminal prompting for password

  4. 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.

    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 (#).

    Mac Terminal with host being added to database

  5. 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).

    Mac Terminal with "File Name to Write: /etc/hosts" prompt

  6. At the bottom of the Terminal, you should see a confirmation 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.

    Mac Terminal with "[Wrote 10 lines]" confirmation

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

    Mac Terminal with script being entered

B: Windows 11

  1. Click your Start button.

    Windows Taskbar with "Start" icon highlighted

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

    Notepad app being searched in "Start" menu

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

    Notepad menu with "Run as administrator" option selected

  4. If prompted by User Account Control, click Yes.

    "Do you want to allow this app to make changes to your device" confirmation window with "Yes" option selected

  5. Click File and choose Open.

    "File" menu with "Open" option selected

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

    File Explorer with folder being opened

  7. Open the hosts file.

    File Explorer with "hosts" file selected

  8. 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 (#).

    "hosts" file open in Notepad with entry being added

  9. Click File and choose Save.

    "File" menu with "Save" option selected

Outcome

Your computer will use the information in the hosts file to translate host names to IP addresses.