Steps to Edit the Hosts File

Windows PC

  1. Open Search: Press the Windows key and type Notepad.
  2. Run as Admin: Right-click Notepad in the search results and select Run as administrator.
  3. Open File: In Notepad, go to File > Open.
  4. Navigate: Paste the following path into the address bar and press Enter: C:\Windows\System32\drivers\etc\hosts.
    • Note: If you don’t see the file, change the file type dropdown from “Text Documents (.txt)” to “All Files (.)”*.
  5. Edit and Save: Make your changes, then press Ctrl + S or click File > Save.

macOS

To edit the macOS hosts file as an administrator, use the Terminal to open the file with sudo privileges. Run sudo nano /etc/hosts, enter your password, make changes using the arrow keys, and save with Control+OEnter, and Control+X.

  1. Open Terminal: Press Command + Space, type “Terminal”, and hit Enter.
  2. Open File with Sudo: Type the following command and press Enter:
    sudo nano /etc/hosts
  3. Authenticate: Enter your Mac user password (it will not appear on the screen) and press Enter.
  4. Edit: Use the arrow keys to move to the bottom of the file. Add your new mappings (e.g., 127.0.0.1 example.com).
  5. Save and Exit:
    • Press Control + O and Enter to save the changes.
    • Press Control + X to exit nano.
  6. Flush DNS Cache (Optional): To make changes take effect immediately, run:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Comments

Leave a Reply