What Is The Hosts File For?
The hosts file is a text file. Your computer uses the hosts file to map hostnames to IP addresses. You can use the hosts file to view a website before DNS changes have propagated (this can take up to 48 hours!), or before you take the site live. Editing it is straightforward.
Editing The Hosts File
To view your site before DNS changes have taken effect, or prior to launching the site to the public, let's assume your domain name is "yourdomain.com".
- Find your website's IP address in cPanel by looking at the Account Information section. You will use the actual IP address you found, but for this tutorial we will pretend your website's IP address is 192.168.1.1.
- In your hosts file, add a line that looks like this:
192.168.1.1Â Â yourdomain.com - When you're done previewing your site, comment out the line by placing a "#" at the beginning of the line. Next time you need to do this, you can just delete the # and save the file.
Windows 10
- Press the Windows key, then type Notepad.
- Right click Notepad and select "Run as administrator".
- In the Notepad app, click "File", then click "Open".
- Enter the following path:Â c:\Windows\System32\Drivers\etc\hosts
- Add a line beginning with your IP address, followed by your domain.
- Save the change in Notepad.
Â
Â
Mac OS X
- Click "Applications", then "Utilities", then "Terminal".
- Open the hosts file by typing "sudo nano /private/etc/hosts"
- If the hosts file is locked, try this command instead: "sudo chflags nouchg /private/etc/host"
- Enter your user password when asked.
- You can add additional domains, subdomains, or addon domains after the primary, such as "192.168.1.1 yourdomain.com www.yourdomain.com blog.yourdomain.com"
- To save the file, press "ctrl"+"o".
- Hit enter to confirm the filename, and "ctrl"+"x" to exit the editor.
Â