The Hosts File: What Is It, How To Edit It Print

  • 21

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".

  1. 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.
  2. In your hosts file, add a line that looks like this:
    192.168.1.1    yourdomain.com
  3. 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

  1. Press the Windows key, then type Notepad.
  2. Right click Notepad and select "Run as administrator".
  3. In the Notepad app, click "File", then click "Open".
  4. Enter the following path: c:\Windows\System32\Drivers\etc\hosts
  5. Add a line beginning with your IP address, followed by your domain.
  6. Save the change in Notepad.

 

 



Mac OS X

  1. Click "Applications", then "Utilities", then "Terminal".
  2. Open the hosts file by typing "sudo nano /private/etc/hosts"
  3. If the hosts file is locked, try this command instead: "sudo chflags nouchg /private/etc/host"
  4. Enter your user password when asked.
  5. 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"
  6. To save the file, press "ctrl"+"o".
  7. Hit enter to confirm the filename, and "ctrl"+"x" to exit the editor.

 



Was this answer helpful?

« Back