...
Skip to main content
Print

How Do I Edit the Local Hosts File on My PC or Mac?

Edit the hosts file on Windows

You can use the local hosts file to view and test a website on a new web server before changing its public DNS.

Open the following file as an administrator:
C:\WINDOWS\system32\drivers\etc\hosts

Edit it with Notepad or Notepad++. Add the server IP address followed by the domain name, for example:

111.222.333.444 example.com www.example.com

Save the file, reopen your browser and visit the domain. If the old website is still shown, clear your browser cache and try again.

Edit the hosts file on a Mac

1. Open Terminal
Press Command + Space, type Terminal and press Enter.

2. Open the hosts file
Run:

sudo nano /private/etc/hosts

Press Enter and enter your Mac password. No characters are displayed while you type the password; this is normal.

3. Add the record
Use the arrow keys to move to a new line and add the required IP address and domain, for example:

111.222.333.444 example.com
111.222.333.444 www.example.com

Place each new record on a separate line.

4. Save the changes
Press Control + O, then Enter to save the file. Press Control + X to close Nano. The hosts file is now updated.
Table of Contents