How To Edit Your Hosts File (Windows, Mac, Linux)

Modifying your hosts file allows you to override the DNS for a domain, useful when you want to test your site prior to DNS propagation / changes. Modifying your hosts file causes your local machine to look directly at the IP address specified for the dpecified domain.

You need to add two entries to your hosts file. Adding the following two lines, for example, point www.mydomain.com and mydomain.com to our shared server IP:

50.28.40.123 www.mydomain.com
50.28.40.123 mydomain.com

Windows

  1. Right-click on Notepad and select Run as administrator.
  2. In Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  3. Make the necessary changes to the file.
  4. Click File > Save to save your changes.
  5. Clear your DNS cache:
    1. Enter cmd in the Start menu search text box.
    2. Right-click Command Prompt and select Run as Administrator.
    3. Run the following command: ipconfig /flushdns.
      • If the command succeeds, the system returns the following message: ?

Mac OS X (10.6+)

  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following line in the terminal window:
    sudo nano /private/etc/hosts
  3. Type your user / password when prompted.
  4. Edit the hosts file.
  5. The file contains some comments (lines starting with the # symbol), and some default hostname mappings (for example, 127.0.0.1 – local host). Add your new mappings after the default mappings.
  6. Save the hosts file by pressing Control+x and answering y.
  7. Your changes will take effect by flushing the DNS cache:
    dscacheutil -flushcache

Linux

  1. Open a terminal window.
  2. Open the hosts file in a text editor (you can use any text editor) by typing the following line:
    sudo nano /etc/hosts
  3. Enter your user / password.
  4. Make the necessary changes to the file.
  5. Press Control+x.
  6. When asked if you want to save your changes, answer y.
  7. Flush DNS:
    sudo /etc/init.d/nscd restart or service nscd restart
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Can I host more than one site per account?

It depends on whether you want each site to have its own domain name or not. If you don't mind,...

What is an Uptime Guarantee?

Server uptime refers to the amount of time in a given period a server stays up and running....

What is FTP? Why do I need it?

FTP - File Transfer Protocol - is one way for you to transfer files to and from your hosting...

What is Spam?

Spam refers to junk email that's sent out in mass quantities. On average, three-fourths of the...

Why shouldn't I go for that unlimited plan? Beware overselling.

If you've been searching for a web hosting provider, you have probably seen some offers that look...