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

A hosts file is a file on your computer that is used to resolve DNS queries before the query even leaves your computer.

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.

hosts files are present in all operating systems, and the method of editing them is different in each.

Windows
  1. Open the Run window by pressing Windows+R.
  2. Type "notepad c:\Windows\System32\drivers\etc\hosts" and run this as an Administrator by then pressing Ctrl+Shift+Enter.
  3. Go to the bottom of your hosts file and add a new line. Add the IP address you wish your domain to resolve to, followed by the domain itself. There should be a space or tab between the IP address and the domain name.
  4. Save the file and go to your domain. You may need to load this in a new window in your web browser, or clear your browser cache to ensure you are loading the correct server.
    Click here to show the screenshot

Mac OS X
  1. Open the Terminal app by going to Applications > Utilities > Terminal.
  2. Type "sudo nano /private/etc/hosts" into the Terminal window. Input your password when prompted. This will open the file in a text editor (Nano) in your Terminal window.
  3. Go to the bottom of your hosts file and add a new line. Add the IP address you wish your domain to resolve to, followed by the domain itself. There should be a space or tab between the IP address and the domain name.
  4. Save the file with Command+O then exit Nano with Command+X. You can then go to your domain. You may need to load this in a new window in your web browser, or clear your browser cache to ensure you are loading the correct server.
    Click here to show the screenshot

Linux
  1. Open your operating system's terminal. On most Linux operating system flavours, you can open this by right-clicking on your desktop and selecting "Open Terminal".
  2. Type "sudo nano /etc/hosts" into the Terminal window. Input your password when prompted. This will open the file in a text editor (Nano) in your Terminal window.
  3. Go to the bottom of your hosts file and add a new line. Add the IP address you wish your domain to resolve to, followed by the domain itself. There should be a space or tab between the IP address and the domain name.
  4. Save the file with Ctrl+O then exit Nano with Ctrl+X. You can then go to your domain. You may need to load this in a new window in your web browser, or clear your browser cache to ensure you are loading the correct server.
    Click here to show the screenshot

Helpful Unhelpful