Linode Library Home
Linode Library RSS Feed
Home :: DNS Services
Print View View Source

Previewing Websites Without DNS

Published: by

Sometimes, you may want to preview your website here at Linode before you update its DNS settings. For example, if you are in the process of migrating your website to Linode, you might want to make sure everything looks good on the Linode side before you redirect your viewers from your old host. This can also be useful when you're creating a brand new website, or want to test your name-based virtual hosting configuration or another DNS-related feature. By making the changes described below, you can test your Linode setup from your local computer without affecting global access to your domain's current location.

Contents

What Is a Hosts File?

The hosts file exists on all major operating systems. You can use the hosts file to force your local computer to look for your domain at Linode, rather than its current location on the Internet. From a technical perspective, the hosts file is used to associate specific hostnames to IP addresses, and takes precedence over the association provided by DNS queries. By manually specifying a specific IP address/hostname pair, web traffic sent to a domain can be directed to a server other than what's specified in the domain's A records. If these terms are unfamiliar, you might want to take a look at our DNS guide.

Note

As an aside, hosts files are sometimes altered on computers infected by malware in order to bring you to malicious servers under the guise of a trusted domain name. It's a good idea to make sure your hosts file isn't altered by anyone but you.

Finding Your Hosts File

The first step is to find and open the hosts file on your local computer. Please note that to edit the file on Linux and Mac OS X systems you will need root access. For Windows systems you will need administrative privileges.

Windows

  1. Begin by opening Windows Explorer. Navigate to C:\Windows\System32\Drivers\etc.

    The path to the hosts file in Windows.
  2. Open the hosts file. Unless you've opened it before and created a file association, it will ask you what program to open it in. Any text editor will work. In the image below we have selected WordPad, which comes by default with Windows.

    Windows asks what program to open the file in.

Mac OS X and Linux

Open a terminal or terminal emulator. You can use your preferred text editor to access your hosts file. This example will use nano, which is installed by default on the latest Mac OS X and most Linux operating systems:

nano /etc/hosts

File:/etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

Don't be surprised if your hosts file looks slightly different. The default configuration will vary depending on your OS.

Finding Your IP Address

Next, you'll need your Linode's IP address.

  1. Log in to the Linode Manager.
  2. Click the Linodes tab.
  3. Select your Linode.
  4. Click the Remote Access tab. The webpage shown below appears.
Select a data center.
  1. Copy the addresses in the Public IPs section.

In this example, the Linode's IPv4 address is 96.126.108.183 and its IPv6 address is 2600:3c03::f03c:91ff:fedf:d693. Unless your Internet service provider supports IPv6, you'll want to the use the IPv4 address.

Updating the Hosts File

Add a new line to your hosts file. It should contain the IP address of your Linode followed by a tab, followed by the domain you want to test. For example:

1.2.3.4     example.com

Please note that on some systems pressing tab will align to the previous lines, and may not appear as a full tabbed whitespace. This is OK.

On OS X systems, you will need to flush the DNS cache if you've already visited or looked up the domain before. You should run the following command from a Terminal prompt:

dscacheutil -flushcache

On Linux systems the need to flush local DNS cache will vary.

Testing

The effect from editing a hosts file should be immediate. In your browser, navigate to your domain:

Our specified domain directed to our Linode.

Once testing is complete or you no longer need the specific direction, you should comment out the new line in your hosts file by adding a # in front of it, or delete the line entirely.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Alex Fornuto on Thursday, January 16th, 2014 (r4118).