Setting your hosts file in Linux
If you have built a site that doesn't currently have a domain, or you've built a site using our hosting but there's a live site hosted elsewhere, using your hosts file is one of the easiest, most effective ways to preview how your site looks on our servers.
What does it do?
Normally when you put 'yourdomain.com' into a browser, it will use a name server to look up what IP address is associated with that domain in order to find the website, however when you're previewing a site under the conditions described above it is not possible to use name servers.
Your hosts file performs a similar task, associating host names with IP addresses, and by adding a single line to that file we can tell your computer “When you go to 'yourdomain.com' look for it at this IP address”
How do I do it?
Before we do anything, you need two three pieces of information
- The domain as it appears on our servers
- The IP address of the server your site is hosted on
- Your Sudo password
When you have those three things open up a terminal and type
And hit enter.
Once you've entered your sudo password you will get a screen that looks a little bit like this
This is your hosts file, and we are going to be adding some information in a new line which will allow you to preview your site without anyone else being able to see what you see.
In an empty gap you will need to add the IP address of your server, “yourdomain.com” and “www.yourdomain.com”. So it will look like this
And that's it! Exit nano (ctrl x) and make sure to save the changes and you're done.
Now when you visit yourdomain.com your hosts file, rather than a name server, will tell your browser where to look for the site.
When you're ready to view the site how everyone else see's it, simply follow through these steps again and remove that line from your hosts file