The Domain Name System (DNS) is the key to locating a website on the Internet. With so much at stake, making changes to your DNS records can be a stressful experience.
Fortunately, there is a way to test DNS-related changes without editing your live records. By modifying your local hosts file, you can preview how your domains will perform on a new server without putting your live site at risk.
In this post, we’ll explore what hosts files are and share some reasons why you might want to modify them. Next, we will show you how to edit hosts files in Windows 10. Start!
Hosts File Overview
A hosts file is a plain text file that maps server or host names to Internet Protocol (IP) addresses. Whenever Windows 10 connects over a network using a hostname, it will reference the hosts file. If Windows finds an entry in this file, it will contact the specified server.
If it doesn’t find a relevant hostname, Windows 10 will resolve the hostname using a Domain Name Service (DNS). This is the process used to get the IP address of the server behind a domain name.
Each hosts file entry has its own line, with the numeric IP address, a space or tab character, and finally the host or domain name. Let’s look at an example of a hosts file entry:
In the example above, the first section denotes the IP address to which this request will be redirected (220.127.116.11). The second section designates the location from which we want to redirect a request (example.com). The final section specifies a comment for this entry. We’re using a hashtag to tell Windows 10 to ignore the comment when reading the local hosts file.
After adding the domain information, your system will resolve to the IP address you specified. In the example above, we are associating the domain name example.com with the IP address 18.104.22.168.
It is worth noting that some programs employ their own techniques to look up hostnames. This means that there is always a chance that you will ignore the hosts file altogether.
is the key to locating a website. With so much at stake, making changes to your DNS records can be a stressful experience. Learn how to safely modify your host files in this guide 👇Click To Tweet What happens when you modify a hosts file? When you modify your hosts file, it causes your local machine to look directly at the IP address specified by you. 🔑 😰
For example, if you want to point mywebsite.com to IP address
22.214.171.124.5, you would add the following: 126.96.36.199.5 mywebsite.com Now, whenever you try to visit mywebsite.com, you will find yourself at
. By editing the hosts file, you
can override the DNS of a domain only on your specific machine
In this post, we will focus on opening your hosts file and adding individual entries. However, it is also possible to replace this file completely. This can be an easy way to block malicious websites or spam in bulk. There are even sites that have published lists lists lists of IP addresses associated with advertisements, hijackers, page counters and other unwanted connections.
You can download one of these pre-prepared lists and copy/paste its contents into your existing hosts file. Alternatively, you can replace your native hosts file with the newly downloaded file. If you opt for the latter, we recommend that you keep a copy of your original file, in case you encounter any strange behavior with its replacement.
Why you might want to modify the Windows 10
You can use your hosts file to test DNS-related changes without having to alter your DNS records. For example, suppose you have migrated to a new server. Before you update your DNS settings, it’s a good idea to check how your domains will look and function on this new server.
However, if you enter your current domain name, it will resolve to your old server. In this scenario, you can modify the hosts file to point the domain to the IP of the new server.
This file can also help test how your website looks on a different server when your DNS hasn’t propagated yet. At Kinsta we provide a temporary URL (sitename.kinsta.cloud), but this can’t mimic everything. For example, by default, a CDN will not work on a temporary URL.
You can also use the hosts file to block certain websites. This can be useful for employers who want to make sure their staff don’t waste time on unauthorized sites like Facebook, Twitter, or YouTube.
While there are fewer technical ways to block access to unauthorized websites, many of these methods are relatively easy to reverse. For example, a tech-savvy child may have minor trouble circumventing parental controls, but modifying the hosts file requires a higher level of technical knowledge.
You can take this a step further and block all websites that offer ads. If you map the addresses of all major ad providers to an unused internal IP address, Windows 10 won’t be able to resolve these addresses. You can then enjoy the web, ad-free.
Finally, some malicious third parties can set up redirects by altering your hosts file. This is known as hosts file hijacking. If you come across strange redirects, then it may be worth checking your hosts file for suspicious entries.
How to make Firefox honor Windows 10 hosts file
If you are using Firefox for Windows, Mozilla’s browser resolves IP addresses slightly differently compared to the other major browsers. By default, Firefox uses DNS-over-HTTPS (DoH).
This is a protocol for performing remote DNS resolution over HTTPS. With this setting enabled, Firefox will use the DOH server as the primary name resolver, rather than checking your local hosts file or DNS resolution.
As a result, the website displayed will always point to the IP address that the Internet deems authoritative for that domain. Even if you edit your hosts file, your changes will have no effect if the DoH server returns a working IP address.
There are many great web browsers that are compatible with Windows 10 and that honor the ready-to-use hosts file. However, if you want to stick with Mozilla Firefox, you can always disable DoH.
To get started, select the Menu button in the Mozilla Firefox browser and go to Settings.
On the next tab, make sure General is selected. Then, scroll down to the Network Settings section and click Settings.
In the pop-up window that appears, scroll to Enable DNS over HTTPS. Then uncheck the attached box.
To save your changes, click OK, and then exit this window. From this point on, Firefox will honor any custom addresses you add to your Windows 10 hosts file.
How to edit your
Windows 10 hosts file (in 3 steps)
There are many reasons why you may need to edit this important file. Regardless of whether you want to block ad networks, verify a new domain, or perform other DNS-related tests, the process will be exactly the same.
Let’s see how to add custom addresses to the Windows 10 hosts file.
1. Find your
Often, you’ll want to change the way Windows 10 resolves the IP address of a site you own. To make this modification, you will need to know the IP address of your website.
If you are a Kinsta customer, you can easily retrieve this information using the MyKinsta dashboard.
Find the domain you want to work with and click it. On the next screen, you will find information about this domain, including its IP address.
Alternatively, you may want to modify the way Windows 10 resolves a third-party IP address. You can retrieve the IP address of any website using tracert.
Tracert is typically used as a network diagnostic tool to help resolve network connectivity issues. However, you can also use it to trace the routes a data packet takes from its origin to its destination, which will reveal the IP address of the destination website.
To start tracert, click the Start icon, and then type command prompt in the search bar.
<img src="https://kinsta.com/wp-content/uploads/2021/10/windows-command-prompt.png" alt="type command prompt in search bar
When the Command Prompt icon appears, click. In the next window, type tracert followed by the URL of the website in question, for example: tracert
Next, press the Enter key on your keyboard. The command prompt will display the IP address of website.com in square brackets next to the URL.
2. Run Notepad as an administrator
In Windows XP and earlier, editing your hosts file was relatively straightforward. You can simply add an exception to your antivirus, open the hosts file in the Notepad app, and then make the changes.
However, Windows 10 added some security measures to prevent users from accidentally modifying this important file. This makes sense, as editing the hosts file could make your favorite websites inaccessible. At worst, it could even make the internet unusable on your machine.
In Windows 10, host information is stored in a plain text file in the System32 internal folder. While you should have no problem opening this file, when you try to save your edits, you may encounter the following error: “You do not have permission to save to this location. Please contact your administrator for permission.”
If you want to save your changes, you will need administrator access. The quickest way to get this is to use a text app that has elevated privileges. In this post, we will use Notepad.
To get started, press the Windows key and type Notepad in the search field.
right-click Notepad and select Run as administrator. Windows 10 will now ask you if you want to allow this app to make changes to your device. Select Yes.
This starts a privileged instance of the Notepad application. Note that you may be prompted to enter an administrative password to reauthenticate.
3. Make the changes
Once you have Notepad open in administrator mode, you are ready to edit the hosts file. On the Notepad toolbar, select File > Open.
<img src="https://kinsta.com/wp-content/uploads/2021/10/notepad-file-open.png" alt="Select File, then select Open on Notepad toolbar
Then, navigate to C:WindowsSystem32driversetchosts. Alternatively, you can copy/paste this file path into the address bar and then press Enter.
If you do not see the hosts file in the /etc directory, you may need to change the file screen type. In Notepad, open the File name drop-down menu and choose All Files.
<img src="https://kinsta.com/wp-content/uploads/2021/10/notepad-all-files.png" alt="Open the File name drop-down menu and choose All Files
Once you have the hosts file in your sights, you’re ready to edit. If this is your first time opening this file, you will see text describing the purpose of the file and how to make modifications, for example: # This file contains the mappings
of IP addresses to host names. Each entry # must be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and host name must be separated by at least one # space.
You can now add your custom IP address and hostname to the end of this file. If you are adding multiple entries, remember to place each entry on a separate line. Once you are satisfied with the changes, you can save and close the hosts file.
To make sure your computer recognizes your edits, it’s a good idea to flush the DNS cache. If you do not currently have a Command Prompt window open, click the Windows button and search for the Command Prompt. In the next window, type the following:
To flush the DNS cache, press the Enter key. Once this process is complete, Windows 10 should use the settings in the new hosts file. Alternatively, restarting your computer should have the same effect.
How to lock your hosts file in Windows 10
By default, you cannot edit the hosts file without administrator privileges. However, it is not impossible to acquire these privileges, especially for tech-savvy people.
If you’re concerned about unauthorized edits, you can add an extra layer of security to your hosts file. For example, you may be using the hosts file to prevent staff from accessing social networking sites and are worried that their restrictions will be circumvented. You may also be concerned about host file hijacking attacks.
In these scenarios, you may want to consider locking the hosts file. While this security precaution is not bulletproof, it will deter third parties from tampering with the file.
To lock your hosts file, navigate to C:WindowsSystem32driversetchosts. Then, right-click on the file and select Properties.
In the Properties window, mark the hosts file as read-only. This will lock the file and prevent anyone from modifying it.
If you want to remove this lock at any time, simply return to the Properties window. You can then remove this read-only restriction.
How to reset your
You can always delete individual entries from your hosts file. Just open the file in Notepad and delete the line in question.
However, sometimes you may need to revert the hosts file to its original state. For example, you may have made several adjustments to your file and don’t want to deselect each of these changes manually. You may also encounter strange redirects, suggesting that your hosts file has become corrupted.
To reset the hosts file to its original state, open File Explorer. In the address bar, type or copy/paste the following:
Then, press the Enter key on your keyboard. At this point, we recommend renaming the original hosts file. This file will serve as a backup, in case you encounter any problems with your new hosts file. You may need to take ownership of this file first, depending on how the privileges are configured on your computer.
The next step is to create a new default hosts file. To accomplish this, create a text file in the %WinDir%system32driversetc directory and name it hosts.
You can now copy/paste the text from the default Windows hosts file, which is provided
by Microsoft: # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each entry # must be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and host name must be separated by at least one # space. # # In addition, comments (such as these) can be inserted on individual # lines or after the machine name indicated by a ‘#’ symbol. # # For example: # # 188.8.131.52 rhino.acme.com # source server # 184.108.40.206 x.acme.com # x client host # local hostname resolution is handled within the DNS itself. # 127.0.0.1 localhost # ::1 localhost
Save this file. As always, you may need to reset your computer or flush your DNS cache for these changes to take effect.
Worried about testing DNS-related changes? 😅Don’t worry. Learn how to use your local hosts archive to preview edits without putting your site at risk 👇. Click To Tweet Summary Making changes to your DNS records can seem like a stressful endeavor. 😄
However, as we discussed in this article, you can safely test your local hosts archive without putting your live logs at risk. In Windows 10, you can do this by looking up your IP address, running Notepad as an administrator, and then making the changes.
If you liked this tutorial, then you will love our support. All of our hosting plans include 24/7 support from our world-class WordPress developers and engineers. We can give you the help you need to succeed, regardless of whether it’s 2:00 a.m. or 2:00 p.m.