Skip to main content

Editing your hosts file to preview your website - Knowledgebase / Website Hosting - Micron21 Helpdesk

Editing your hosts file to preview your website

Authors list

Overview:

Editing the "hosts" file on your computer allows you to bypass DNS queries and resolve a specific domain to an IP address on your local machine. This guide explains how to edit the "hosts" file on Windows, Mac OS X, and Linux.

This can be incredibly useful when you are building or testing a website but do not want to make changes to your existing DNS to point public traffic to your work in progress.  Such "hosts" files are present in all operating systems, and the method of editing them is different in each.

Windows method:

  1. Open the Run window by pressing Windows+R.

  2. Type "notepad c:\Windows\System32\drivers\etc\hosts" and run as an Administrator by pressing Ctrl+Shift+Enter.

  3. Add a new line to the bottom of the hosts file with the IP address you wish your domain to resolve to, followed by the domain itself. Separate the IP address and domain name with a space or tab.

    1. For example, “123.456.78.9 domain.com.au”

  4. Save the file and go to your domain in a browser. You may need to load it in a new browser window or clear your browser cache to ensure you are loading the correct server.


Mac OS X method:

  1. Open Terminal app by going to "Applications > Utilities > Terminal".

  2. Type "sudo nano /private/etc/hosts" into the Terminal window and input your password when prompted.

  3. Add a new line to the bottom of the hosts file with the IP address you wish your domain to resolve to, followed by the domain itself. Separate the IP address and domain name with a space or tab.

    1. For example, “123.456.78.9 domain.com.au”

  4. Save the file with Command+O, then exit Nano with Command+X.

  5. Go to your domain. You may need to load it in a new browser window or clear your browser cache to ensure you are loading the correct server.


Linux method:

  1. Open the terminal on your Linux operating system.

  2. Type "sudo nano /etc/hosts" into the Terminal window and input your password when prompted.

  3. Add a new line to the bottom of the hosts file with the IP address you wish your domain to resolve to, followed by the domain itself. Separate the IP address and domain name with a space or tab.

    1. For example, “123.456.78.9 domain.com.au”

  4. Save the file with Ctrl+O, then exit Nano with Ctrl+X.

  5. Go to your domain. You may need to load it in a new browser window or clear your browser cache to ensure you are loading the correct server.



Helpful Unhelpful