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.
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.
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.
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.
Begin by opening Windows Explorer. Navigate to C:\Windows\System32\Drivers\etc.
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.
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:
## # 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.
Next, you'll need your Linode's IP address.
In this example, the Linode's IPv4 address is 22.214.171.124 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.
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:
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:
On Linux systems the need to flush local DNS cache will vary.
The effect from editing a hosts file should be immediate. In your browser, navigate to your domain:
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.
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.
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).