How to Edit your Hosts File and Preview a Website Under Construction — Innobella Media

Paul Freeman-Powell
4 min readSep 24, 2019

These days, it’s common practice to design, develop and build a new website ‘live’; that is, to build it in-place on the web server on which it will be hosted and call its home after launch. This makes sense for a number of reasons as you can properly set up and test everything before launch, and it also saves reinventing the wheel when you do want to launch, as it’s already in place to start with. It’s a bit like building a house on the plot of land it’ll stay on.

This is all well and good when it’s a brand new website with a new domain name which hasn’t ever been used for anything before. We can simply hide it behind an “under construction” banner, meaning no-one apart from those we want to can access the website until it’s ready to be seen by the world.

But what if you already have a website — eg., mywebsite.com — and you need the old one to stay accessible whilst the new one is being built?

How Domain Names & DNS Work

Without getting too technical, the way website domain names and web hosting work is like this: every computer on the internet (including web servers) has its own unique identifier, called an IP address. You’ll probably have seen these, they’re a series of 4 numbers with dots in between like 216.58.212.206

That’s not very easy to remember for humans, though, and it’s nice to be able to brand things so instead, we use a domain name like “mywebsite.co.uk” instead. When you type that in your address bar (or click a link), behind the scenes your computer looks up the domain name in what is essentially a big phonebook for the Internet, and this tells it where to go, eg. 216.58.212.206. The webserver at 216.58.212.206 sees the request coming in, knows it has come via “mywebsite.co.uk” and thus knows which website to display to you (because there could be many hosted on the same server).

Overriding DNS for your own Computer

If you’re building a new website and hosting it on a new, different server then the final stage of the process — to “launch” the website — will be to update that big “phonebook for the Internet” to tell everyone the new IP address to associate with that domain name, mywebsite.co.uk.

However, you can override this just for you whilst developing and building a new website, so that your computer sends requests to the new server instead, and you’ll see the new website, but everyone else in the world will see the old website until you’re ready for the big unveil.

To do this, we need to edit something called your hosts file on your computer.

The method varies depending on which operating system you use.

Windows Users

  1. Click Start and type in “Notepad”. Then right-click Notepad and choose “Run as Administrator”.
  2. Click “Yes” to the security prompt
  3. Inside Notepad, click File then Open

Paste in the following file path, then press Open:

C:\Windows\System32\Drivers\etc\hosts

At the bottom of the file, add the following two lines:

xxx.xxx.xxx.xxx domain.com
xxx.xxx.xxx.xxx www.domain.com

Replace the xxx values with the IP address of the new server, and the “domain.com” with the actual domain name of the website. You’ll notice we’ve included 2 lines; one with www. and one without.

Save the file, and now your computer will direct all requests for that website to the new server, and you will be able to see the new website.

Mac Users

If you’re using Mac OS, open a Terminal window by clicking Applications, then Utilities and looking for Terminal.

Then, type the following line:

sudo nano /private/etc/hosts

You’ll have to type your password to authorise access to this system file. Then, do the same as above (see ‘Windows Users’).

Linux Users

If you’re on Linux, the method to open the hosts file is broadly the same as on a Mac (because Mac OS is Unix-based), and you’ll want to add the same lines as both Mac and Windows users. The only difference is the path to the file may be different, so try:

sudo nano /etc/hosts

Conclusion

So, next time you’re having a new website built your web designer might ask you to edit your hosts file in order to be able to see the new website. As you can see, it’s quick and easy to do so and ensures that the rest of the world won’t see it until it’s ready!

Originally published at https://www.innobellamedia.uk on September 24, 2019.

--

--

Paul Freeman-Powell

Award-winning tech, web & video creator. I run https://www.innobellamedia.uk/ & host YouTube.com/SwitchedOnNetwork/. I’m @paulfp on Twitter & Instagram.