How to Modify Your Hosts File so You Can Work on a Site That Is Not Yet Live
The usual progression for building a website is
- Choose a domain name for your website.
- Purchase the rights to use that domain name from a registrar.
- Choose a hosting company to host your website.
- Build your website.
- Contact your registrar to direct the DNS servers to point web requests for content on your site to the server that's hosting it.
Many hosting companies supply a temporary alias that is added to your domain name so you can work on your site before making it live to the rest of the world. If you don't have a temporary alias or don't want to use it, but do need to access your website before contacting your registrar, you can modify the hosts file of your local machine.
The hosts file is a file that all browsers look at when getting a new website request prior to going to their DNS server. When you enter a website in your browser, your PC first looks at the hosts file for information and if it doesn't find the website there, it asks the ISP's DNS server to locate the IP address of the site.
Modify the Hosts File on a Windows 8 PC
Windows 8 protects the hosts file from modification by malicious programs. To modify it, you must run Notepad as an administrator.
- Press the Windows key on your keyboard, type Notepad, but do NOT press Enter.
- Right click on Notepad and choose Run as Administrator.
- Log in (or have a someone with admin credentials log in).
- Click File > Open.
- Navigate to C:\Windows\System32\drivers\etc.
- In the lower right corner of the Open dialog box, change the Text Documents (*.txt) to All Files.
- Double click on hosts.
- Click on Start > Run > c:\.
- Navigate to c:\Windows\System32\drivers\etc and double click on hosts.
- Open it with Notepad..
- Add the IP address of the server that is hosting your website.
- Press Tab and add the domain name of your website.
- Save the hosts file.
- If you are unable to save it due to security policies on your computer, save it with a different name, like hosts2. Close Notepad. Delete the original hosts file and rename hosts2 to hosts.
- You should be able to access your website (without a temporary alias) from your local machine by entering the domain name in the address bar of your browser.
- Repeat the above process on any other machines you will be using when creating content for the site prior to making it live.
Modify the Hosts File on a Mac or Linux
- Open the Terminal app.
- Type sudo nano /private/etc/hosts. for Mac, sudo nano /etc/hosts for Linux.
- Enter the IP address and domain name on a new line at the end of the file, as shown above.
For additional instructions on how to add hosts to the local hosts file in Mac OS X see http://support.apple.com/kb/TA27291.