How to edit your host file

Applies to:
Domains
Professional Hosting
Business Hosting
Reseller Hosting
VPS Hosting
WordPress Hosting

Difficulty:
Easy

Time Needed:
10 minutes

Introduction

This is a quick step-by-step guide to editing your host file. Editing your host file is a great way of viewing a specific web server prior to updating your DNS, or whilst it is propagating.


Article Contents


How to edit a host file on Windows


Step 1

Click on the 'Start' button

When running Windows, click on the start button (or the Windows icon), usually located at the bottom left of the screen.

Click on the 'start' button

Step 2

Choose 'All Apps'

On the start menu, choose 'All Apps' from the list of options. Then click on the option labelled 'Windows Accessories'

Choose 'All Apps'

Step 3

Select 'Notepad'

After you have clicked on 'Windows Accessories', you will be presented with a list of applications. Locate 'Notepad' from the list of icons, and right click on it. Then choose 'Run as administrator' from the context menu.

At this point a dialog box may open, asking you 'Do you want to allow the following program to make changes to this computer'. Simply click 'Yes' to proceed.

Select 'Notepad'

Step 4

Open the host file

In Notepad, click 'File', then 'Open'.

Open the host file

Step 5

Locate your host file

From the window that opens, click on 'Text Documents (*.txt)' and choose 'All files'. Then locate and open the following file:

c:\Windows\System32\Drivers\etc\hosts
Locate your host file

Step 6

Edit the host file

This will open your host file. To add a new server or domain, move the cursor to the bottom of the file, then enter the IP address of your server, press the 'Tab' key, then enter your domain name.

The following is an example, you will need to update these to your relevant IP address and URL.

127.0.0.1  yourdomain.com

When you have entered the relevant IP address and url, click 'File', then 'Save' to save your changes.

Then open your web browser and enter the domain you added to your host file. If the site changes from the one of the public can see, to the one on your new server, then you have edited the host file successfully.

Edit the host file

How to edit your host file on OS X


Step 1

Choose 'Go'

When running OS X, click on the Finder icon, then choose 'Go' from the menu bar.

Choose 'Go'

Step 2

Open 'Utilities'

From the drop down menu, select 'Utilities'.

Open 'Utilities'

Step 3

Select 'Terminal'

This will then open the 'Utilities' settings. Locate the icon labelled 'Terminal', and double click on it.

Select 'Terminal'

Step 4

Run the command

This will bring up your command prompt. Simply enter the following, and press the 'Return' key.

sudo nano /etc/hosts
Run the command

Step 5

Edit the host file

This will open your host file. To add a new server or domain, move the cursor to the bottom of the file using the arrows keys. Once you have moved the cursor the the end of the file, enter the IP address of your server, press the 'Tab' key, then enter your domain name.

The following is an example, you will need to update these to your relevant IP address and URL.

127.0.0.1  yourdomain.com

When you have entered the relevant IP address and url, hold down 'CTRL' key and press the 'O' key, then press the 'Return' key to save your changes. Then simply hold down 'CTRL' key and press the 'X' key to exit and return back to your command prompt.

Edit the host file

Step 6

Flush your DNS

For the final step, simply enter the following command to flush your Mac's DNS cache.

sudo killall -HUP mDNSResponder

After running the above command, return back to your web browser and enter the domain you added to your host file. If the site changes from the one of the public can see, to the one on your new server, then you have edited the host file successfully.

Flush your DNS

Was this helpful?

   
16 people found this article helpful
34SP.com Rated 9.2 out of 10 based on 172 reviews Trust Pilot