Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Test Management and Windows Last updated: November 30, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Let’s check out how to edit hosts file on Windows 10/11 to test a website locally without making DNS changes.

Hosts files act as the local DNS servers. But before going further, let’s check out this incident involving Jack.

Jack was a website admin at a regional eCommerce store in Toronto, Canada. He was asked to ensure the transfer to a different web host goes smoothly.

He did it perfectly, and the site was live soon after DNS changes were made. The only issue was missing images from a significant number of products.

While they mitigated the issue as soon as possible, a few thousand dollars piled up as lost revenue. And Jack was asked to leave his job.

His mistake, you ask?–Skipping a simple but crucial step to test the new website before modifying the DNS records.

Hosts File

Jack could have averted the crisis by making a single line entry in the host file on his Windows PC using Notepad, similar to this:

241.32.87.165 domainname.com

This would’ve helped him to check the migrated website without touching the live online store.

Hosts file keeps local DNS records every computer checks before contacting DNS servers. The purpose is a faster connection without increasing latency.

How does Hosts File Work?

Let’s take another example.

Suppose you have to go to a newly launched supermarket but are confused about its name and exact address. Keeping Google Search aside for a moment, you can consult your brother (host file) or a neighbor (DNS server).

The second method will involve extra time (latency), and asking the brother is quicker.

Similarly, when we type a domain name (ex. geekflare.com), our computer being a machine, needs the associated IP address to load the website in the browser.

First, it searches the local host’s file. If it lacks the information needed, the query is passed on outside.

After that, those DNS servers match the domain name with the IP address and send back the response. And finally, we see the website loaded.

By editing the hosts file we trick our local machine into believing the migrated website is the live one. It also avoids connecting our PC and the DNS server for that specific query.

So, when we visit that website, it loads from the IP address listed in the host file and not as per the DNS records at the domain registrar.

This helps in testing if everything is working flawlessly before going live.

Editing Hosts File on Windows

Hosts file is located inside C:\Windows\System32\drivers\etc

hosts file folder

Although it lacks a text file extension, you can edit this in any text editor. However, the process is a bit long.

You will open this file in Notepad to make necessary changes, save it somewhere else, delete the original file, and finally move the modified file in there.

But we’ll take a shortcut.

Start by opening Notepad as administrator.

using notepad to edit host file

Then click All Files, then Open in the drop-down, and browse the hosts file directory:

hosts file folder

Now follow the first step and change it to All Files (*.*), because there isn’t a text file in the folder, so it will feel empty at first.

Next, select the hosts and click Open.

The editing host file part includes entering your website name and server’s IP address to which you’ve moved the files:

hosts file editing

Remember not to put #, as this would make the statement a comment which won’t work.

Finally, press Ctrl+S to save the changes and exit.

Verification

Now you can log on to the website and see any issues.

But wait! How do you know it’s loading from the new server and not the live one?

To verify that and check the new web address, you must close the browser first.

Then open the command prompt and type. ipconfig/displaydns.

host file edit check in command prompt

The domain name will be listed against the Record Name and the IP address with A (Host) Record.

The displaydns list may be long, and you can flush DNS to delete existing records. This is a single-step, completely harmless process where you open the command prompt and type ipconfig/flushdns.

Finally, reopen the browser, and enter the web address to visit the test site.

While the process was easy, there is a simpler alternative if you don’t mind using freeware.

Hosts File Editor

Host File Editor comes as an installation and a portable application. This is very intuitive and will be handy if you do this often.

hosts file editor

You can start entering the details in the grey fields and click save at the top. And yeah, don’t forget to check the entries; else, they will show as comments in the host file.

Lastly, you can delete the files created by this application if you choose to go back to the conventional way.

There will be three named hosts.bak, hosts.disabled, and one archive folder. Or save the folder before using such applications as a backup.

Conclusion

Host file editing in Windows simplifies website testing before changing the DNS records. You can use a text editor such as Notepad and make necessary changes applicable to the local machine.

Though there is another way to do it with a temporary URL, that method has some drawbacks, especially if you’re using a content delivery network (CDN).

And while the screenshots refer to Windows 10, it will also work perfectly in Windows 11.

PS: Check out the merits of DNS filtering and how it can save your business from cyberattacks.

  • Hitesh Sant
    Author
    Hitesh works as a senior writer at Geekflare and dabbles in cybersecurity, productivity, games, and marketing. Besides, he holds master’s in transportation engineering. His free time is mostly about playing with his son, reading, or lying… read more
Thanks to our Sponsors
More great readings on Test Management
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Monday.com is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder