How To Edit Your Hosts File on Mac or Windows

how to update hosts file

Why Edit Your Hosts File?

Updating the hosts file on your computer is useful for development purposes. You can preview how your site will look on another server without affecting the live site that users view.

It is particularly useful when creating a development site for WordPress since it uses absolute urls. Creating the development site on a new server with the same domain means that you will not have to complete a database find and replace query when you’re ready to move the new site live.

In order to update the host your domain loads from, you will need to know the IP address for the new server you want to preview.

How to Edit Your Hosts File on Windows

1. Select Start and search for “Notepad”.

2. Right-click Notepad and select “Run as administrator”.

3. Click “File” and select Open.

4. In the lower right dropdown, change Text Documents (*.txt) to All Files (*.*)

5. Go to the Windows Hosts File location: C:\Windows\System32\Drivers\etc and open the hosts file.

6. Add the new IP address and the URL

7. Save the file.

How to Edit Your Hosts File on Mac

1. Open your spotlight search and search for “Terminal”.

2. Copy and paste the command: sudo nano /private/etc/hosts and hit enter.

3. Provide your password when prompted.

4. Add the new line with the server IP address and the website URL:

5. Select control-o to save the file and hit enter.

6. Select control-x to exit the editor.

Flush Your DNS

Once you've edited your hosts file, it is advisable to flush your DNS cache otherwise your browser may continue to direct to the old server.


1. Go to the Start menu and type "cmd."

2. Right-click the Command Prompt option and "Run as Administrator".

3. Type the command below and hit enter:

ipconfig /flushdns



  1. Open the terminal and type the command below and hit enter:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

About YellowWebMonkey

YellowWebMonkey Web design offers reliable website design, SEO and digital marketing services for Joomla, WordPress and Shopify sites. We strive to be a one-stop shop for all your web needs.

Recent Posts

Follow Us