How to Edit Your DNS Hosts File

Posted on by David Singer | Updated:
Reading Time: 8 minutes

One of the most powerful tools available to anyone working on their site during a migration is their computer's "hosts" file. The hosts file is used to map domain names to IP addresses, and can be used as an alternative to DNS. It also allows you to specify the IP address to which a website resolves on your computer, regardless of what may be published in the site's DNS zone file.

Why Edit Your Hosts File?

Modifying your hosts file lets you view and test a site on one server while the rest of the world continues to see the site on another. That makes it an essential tool when migrating your website. With this method, you're able to ensure that:

  • Everything on the site works as expected on the new server before you update the DNS records
  • The visitors to your existing website will not be affected by any potential issues related to different server environments before you've had a chance to resolve them


It's actually a very simple process. Let's take a look at an example hosts file:       localhost    broadcasthost
 ::1             localhost

In this case, the first three entries are defaults used to configure the local network interface. You may have more or less local entries in your hosts file. You do not need to worry about them other than to note their presence. Any custom entries will go at the bottom of the file, and in this case, you can see that we have added a custom entry to the end of the file already:

My custom entry specifies that any request made from my computer (via a web browser or SSH, email, or FTP client) for or will be directed to the IP address I've specified: To redirect your specific request, you must add your own custom entry to the end of your file using the same format.

The line for your custom entry will consist of three elements.

  • The IP address of the server to which you want the domain name to resolve on your computer
  • A tab or space
  • The domain name(s) meant to resolve to the specified IP address

If you're migrating to a Liquid Web server, your migration technician will supply you with the information to add. Simply copy and paste the line into your hosts file. If your migration involves multiple IP addresses, you will have one line for each IP address, regardless of how many domain names share it.

Do not remove or modify any existing local entries in your hosts file. You will only be adding a new line or lines at the bottom of the file for testing, and then removing the lines you’ve added once testing is complete.

Step 1.
Edit Your Hosts File

Firefox now uses DNS over HTTPS (or DOH) by default. That means instead of checking your local hosts file or even your DNS resolver. Firefox simply makes the DNS request over HTTPS from within the browser. This behavior guarantees that the website displayed points to the IP address that the Internet sees as authoritative for that domain. There are two primary ways to avoid this behavior while testing your new site. First, use a different browser. Chrome, Edge, Safari, and many others do not have this setting enabled by default and will continue to work as expected with a modified hosts file. The second method is to disable DOH in your Firefox browser. Follow the directions below to disable this setting. 1. Open your Firefox browser. 2. Click the menu button and select Options. 3. In the General panel, scroll down to Network Settings and click the Settings button. 4. In the dialog box that opens, scroll down to Enable DNS over HTTPS. 5. Uncheck the box beside Enable DNS over HTTPS. 6. Click OK to save your changes and close the window. You can now edit your Hosts File and proceed with testing your new site like you normally would. We do recommend re-enabling this feature as it keeps you safer while browsing.

The location of your computer's hosts file depends on your operating system. Because it is a protected file that must be edited with administrative privileges, the procedure for editing also varies by the operating system.

Click a link below to skip ahead to the specific instructions for your operating system. If you experience difficulties editing your hosts file or are not seeing the sites on the new server after you've followed the steps below, check out the Bonus: If All Else Fails section at the end of this article.


Here are the video instructions for editing your Windows hostfile!

How to edit your Windows hostfile

In Windows, the hosts file is located at C:\Windows\System32\drivers\etc\hosts. You will need to edit the file with administrative privileges.

Step 1.
Click the Windows button and type 'Notepad' in the search box.

Step 2.
Right-click on 'Notepad' and then 'Run as Administrator'.

Step 3.
Choose 'Yes' on the User Account Control pop-up.

Step 4.
In Notepad, choose 'File' then 'Open'.

Step 5.
Click the address bar at the top and paste C:\Windows\System32\drivers\etc\hosts - then choose 'Enter'.

Step 6.
Choose Notepad from the list and then OK.

Step 7.
Add the appropriate IP and hostname (given by the Migration team) at the end of your hosts' file, select Save, and close the file.

Step 8.
Next, you will want to flush your DNS cache so you don't have to log out and back in for the changes to take effect.

Step 9.
Lastly, open an elevated command prompt as above, and enter the following command at the prompt.

ipconfig /flushdns

Mac OS X

On Mac OS X, your hosts file is located at: /private/etc/hosts. You will need administrative privileges to edit the file, which you can do manually or by appending the new entry directly from the command line.

Step 1.
First, launch Terminal from Spotlight search (Command+Space, or click on the magnifying glass icon in your menu bar) or the Utilities folder in Applications on many versions of Mac OS X.

Step 2.
To edit the file manually, enter the following command in Terminal.

sudo nano /private/etc/hosts

Step 3.
Enter your password when prompted and press Enter to authenticate and open the file.

Step 4.
Now add the new line of information. Use your arrow keys to navigate to the bottom of the file. Type in (or paste) the IP address and website name you intend to redirect.

Step 5.
Press Control+O to save (Write Out) the file. Then press Enter to overwrite the existing file and finally, press Control+X to exit.

If you prefer to simply append the entry to the existing file, you can do so with one command, substituting your server’s IP address and domain name for the ones in this example below and then enter your password when prompted.

echo "" | sudo tee -a /private/etc/hosts >/dev/null

While you still are in Terminal, you should flush the DNS cache so you don't have to log out and then log back in for the changes to take effect. For the current version of Mac OS X, you can do that with this command.

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

On the first few releases of Mac OS X Yosemite (versions 10.10 through 10.10.3), the command needed to flush the cache is as follows.

sudo discoveryutil mdnsflushcache; sudo discoveryutil udnsflushcaches

For version-specific instructions in older versions of Mac OS X, see the information here: How To Flush Your Local DNS cache.


On Linux, you can find the hosts file at: /etc/hosts. Depending on your distribution, you likely will need administrative privileges to edit the file.

You can edit the file manually with vi, vim, or nano, or append the new entry directly from the command line.

Using Vim

Step 1.
Open a terminal and enter the following command followed by the return key, and then enter your password to authenticate if prompted.

sudo vim /etc/hosts

Step 2.
Add the new entry at the end of the file, then type :wq to save and close the file.

In vim, you can press “i” or “a” to enter text insertion mode. Pressing the escape key (Esc) on your keyboard returns you to command mode. For a refresher on editing files with vim, see New User Tutorial: Overview of the Vim Text Editor.

Command Line

Step 1.
If you prefer to simply append the entry to the existing file, you can do so with one command, substituting your server's IP address and domain name for the ones in this example below. If not logged in as the root user, you may need to enter the root password to complete the command.

echo "" | sudo tee -a /etc/hosts >/dev/null

Step 2.
After running the above command, we need to flush the DNS cache. This command can vary widely depending on your specific distribution and version.

  • Many Ubuntu and Debian-derived distributions use:
sudo service dns-clean restart.
  • Other Linux distributions using NSCD (Name Service Caching Daemon) may need to use one of the following commands.
sudo service nscd restart 
sudo systemctl restart nscd.service
nscd -I hosts

Step 2.
View the Site on its New Server

At this point, your website should resolve on your local computer to the IP address specified in your hosts file instead of the IP address specified in the site's DNS record. If you're not seeing the site on the new server, it could be because your browser is serving a cached version of the page. In this case, we can use the following steps to clear your cache.

  • Manually clear your browser's cache (typically Control+Shift+Delete or Command+Shift+Delete). For browser-specific instructions, see Clearing Your Browser Cache.
  • Use a private browsing window to view the site
  • View the site in another browser
  • Log out of your computer and then log back in

If you're uncertain whether you are seeing the new site or the old, you can confirm the IP address of the site you're viewing using a browser add-on. There is no shortage of such extensions, most of which will display a site's IP address right in the browser's menu bar. For your convenience, a few are listed below:

Liquid Web has no association or affiliation with any of these browser extensions or their developers and cannot guarantee compatibility or performance. They’re simply among the most commonly used tools for this purpose, and their inclusion in this list does not constitute an endorsement. Please be sure to read the notes and reviews on the individual plugin pages to determine which you prefer to use.

Step 3.
Test the Site on its New Server

Now that you can see the site on its new server, you must thoroughly test it to determine whether everything works as expected. It is common to see some issues and error messages when testing a migrated site. There's no cause for alarm — typically only minor adjustments to the server configuration, such as enabling an Apache module or adjusting a php directive, are needed to resolve them.

To ensure that all your site's software, scripts, and plugins work correctly on the new server, be sure to use the following information checklist to verify the website's info.

  • Visit each link on your home page and ensure that it loads without error
  • If your site runs a CMS such as WordPress or Magento, log into the administrative area
  • If your site has a shopping cart, add an item and test your checkout process
  • Test any forms on the site
  • Create a post
  • Comment on a post
  • Upload a file

Should you notice any issues when performing the above tests:

  • Note the full URL of the page
  • Note the specific error message or problem
  • Provide that information to the person performing your migration. If Liquid Web is handling the migration, simply paste that information into your migration ticket to ensure that the proper adjustments are made as quickly as possible.

Alternative Option

If you are unable to successfully modify your hosts file to point your website to a new IP address, there remains an alternative option: View the site through an external service.

SkipDNS is an online service that allows you to preview a website without changing the DNS or hosts file. It works by creating a link between your site's URL and a newly created link that is previewable by anyone with which you share it. This proxy allows you to generate a preview of the website and a shareable link before propagating the DNS.

You can create a single link for free that would expire at a later time. SkipDNS paid plans provide a set number of links that do not expire along with other features depending on your plan.


Modifying your hosts file is an excellent method for previewing your website during any transitional modification. It is usually a simple procedure but should you have issues you can contract Liquid Web support.

Should you have any questions regarding this information, we are always available to answer any inquiries with issues related to this article, 24 hours a day, 7 days a week 365 days a year.

Our Support Teams are filled with experienced Linux technicians and talented system administrators who have intimate knowledge of multiple web hosting technologies, especially those discussed in this article.

If you are a Fully Managed VPS server, Cloud Dedicated, Private Cloud powered by VMware, Private Parent server, Managed Cloud Servers, or a Dedicated server owner and you are uncomfortable with performing any of the steps outlined, we can be reached via phone @800.580.4985, a chat or support ticket to assisting you with this process.

Avatar for David Singer

About the Author: David Singer

I am a g33k, Linux blogger, developer, student, and former Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article