How to Prevent Hosts File Override in Windows 10

I’m currently taking a Laravel course, and I’m using an environment which, among other things, requires me to edit the hosts file in Windows.

I have to map some hostnames to some IPs in there, like this: laravel.test

The problem is that after, like, an hour, the hosts file gets automatically overridden and the lines are commented out with a hashtag, like this:

# laravel.test

That’s very annoying, but, fortunately, there’s a solution.

What Causes the Hosts File Override?

Most likely, it’s your antivirus, especially if you’re using Bitdefender, as I do.

It does that to prevent DNS hijack attacks.

Prevent the Hosts File from Getting Overridden in Windows 10

Here are several ways to fix this issue.

Method 1

Go to the hosts file, right-click on it, make it Read-only, then click Apply.

windows 10 hosts file read-only

This is what I did and it worked. It’s the simplest way.

Method 2

Go to the Security tab, click Edit, select All Application Packages, then check the Deny box for the Write permission.

deny writing permission hosts file windows 10

I didn’t test this myself, but it should work because you’re denying applications (e.g. antivirus) writing permission for the file.

If it doesn’t work, do the same but for SYSTEM. It might be your system that overrides the hosts file, not your antivirus or other application.

Method 3 – If you’re using the Bitdefender antivirus

Go to Settings > Advanced and disable Scan hosts file.

disable scan hosts file bitdefender
Bitdefender Total Security 2020

Where this feature is, or if it exists at all, depends on your Bitdefender version.

I think it’s safer to just make the file Read-only, rather than disabling the scanning feature, so I recommend trying that first.

That’s a Wrap

I hope you found the guide useful and you managed to prevent the hosts file from getting overridden in Windows 10.

If you have questions or thoughts, please leave a comment or send me a message using the contact page.

Don’t forget to share the post to help out others!

Leave a Comment