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:
192.168.10.10 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:
# 192.168.10.10 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.
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.
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.
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 some info is outdated or incorrect, or you have anything to add, say or ask, please contact me via Twitter or email.
Looking for a modern & optimized presentation website?
Hire me on Fiverr