- The hosts file and LMHOSTS allow local control of name resolution and can cause failures if they are corrupt or misconfigured.
- Windows 10 requires editing these files with administrator privileges and it is possible to lock them to read-only or restore them to their original state.
- Tools like tracert, flushing the DNS cache, and disabling DNS over HTTPS in Firefox are key to testing and debugging changes.

When name resolution problems start occurring on a Windows network, one of the usual suspects is the Hosts and LMHOSTS files . Although almost everything is handled by DNS these days, these files are still there, silently influencing how your computer translates names into IP addresses, and if something goes wrong, they can leave you without access to servers, applications, or even the internet.
Furthermore, the permissions and security of Windows 10 and Windows Server complicate matters even more: you might find yourself unable to edit Hosts or LMHOSTS even as an administrator, encounter strange errors related to the sample file lmhosts.sam , or experience odd behavior from browsers like Firefox that bypass the hosts file using DNS over HTTPS. Let's take a step-by-step look at how these files work, what typical problems they cause, and how to fix them without driving yourself crazy.
What are Hosts and LMHOSTS files in Windows?
Windows uses two local name resolution mechanisms : the hosts file and the lmhosts file (in addition to its sample version lmhosts.sam ). Both are plain text files that allow you to associate hostnames or computers with specific IP addresses, but they have slightly different approaches and uses.
The hosts file is used to map domain names or hostnames to IP addresses, bypassing the DNS server. Each line in the file contains an IP address, one or more hostnames, and optionally a comment. For example:
120.0.0.0 ejemplo.com #Ejemplo
In that example, the specified IP address (120.0.0.0) is the destination for any request made from that computer to example.com . If the name appears in the file, Windows will use that IP; otherwise, it will use DNS. This ability to override standard DNS resolution is very useful for testing, server migrations, or blocking unwanted websites.
The LMHOSTS file, on the other hand, is designed for NetBIOS and legacy or mixed environments where NetBIOS names and WINS resolution are still used . It allows you to statically define associations between NetBIOS names and IP addresses before resorting to WINS or other resolution methods.
The lmhosts.sam file is simply a sample file that Microsoft includes with the system. Although it is sometimes incorrectly labeled as a "DLL", it is actually sample text that explains how to use LMHOSTS and serves as a template. However, errors or corruption in this file may also be associated with failure messages in certain software installations.
When does it make sense to use LMHOSTS today
In modern, well-configured networks with properly functioning DNS , relying on LMHOSTS is becoming less common. If your infrastructure already has well-managed DNS servers, the use of static LMHOSTS files is usually a relic of earlier times, when DNS wasn't deployed across the entire network or when NetBIOS and WINS were the primary operating systems.
If you inherit an old network riddled with patches , it's relatively common to find servers with a massive, outdated LMHOSTS file, full of entries that are useless or point to hosts that don't even exist. In this scenario, you have two options: carefully clean up the file or delete its contents to force the use of DNS.
Before deleting a large LMHOSTS file , it's advisable to check for legacy hardware or applications that still rely on static NetBIOS resolution. If the entire infrastructure is running modern Windows Server (2008 R2, 2012, 2016, 2019, etc.) and the internal DNS is functioning correctly, LMHOSTS is likely no longer necessary, but it's wise to verify that there are no explicit references to it in older configurations.
To create "dummy names" or temporary access , it's more common nowadays to use the hosts file instead of LMHOSTS. The hosts file is better suited to DNS-based infrastructures and is more intuitive when working with web domains or subdomains.
Common problems when editing Hosts and LMHOSTS
One of the most frequent problems in Windows 10 and Windows Server It appears when you try to modify C:\Windows\System32\drivers\etc\hosts o lmhosts and you encounter access denied errors, even though your user belongs to the system administrators group.
When trying to save changes to the hosts or lmhosts file , messages like the following may appear:
- “Access to C:\Windows\System32\drivers\etc\hosts was denied.”
- “The file C:\Windows\System32\drivers\etc\hosts could not be created. Please ensure that the path and filename are correct.”
These errors occur even if your account is an administrator , because Windows protects certain system areas from direct writing by applications that don't run with elevated privileges. The classic Notepad program, if opened normally, doesn't have sufficient permissions to overwrite the file.
In addition to this permissions problem, there are other more subtle ones , such as the fact that some applications or installers can manipulate the sample file lmhosts.sam , and when it is damaged or disappears, it can trigger "component not found" or "could not load lmhosts.sam" errors in programs that expect to find that sample file in temporary or system paths.
Typical messages related to lmhosts.sam include things like “Access violation at address: lmhosts.sam”, “Failed to load lmhosts.sam”, “The lmhosts.sam file is missing or corrupt”, or warnings that an application cannot start because the component is missing and needs to be reinstalled.
Errors related to lmhosts.sam and common causes
Although lmhosts.sam is a simple sample file , it may be referenced by installers or configuration processes. When this file is not found in the expected path, is corrupted, or has been deleted as a "shared file," runtime errors or component loading failures may occur.
Common reasons why lmhosts.sam disappears or becomes corrupted include:
- Accidental deletion by the user or by a cleaning script.
- Uninstalling another program which considered lmhosts.sam as a shared file and deleted it along with its components.
- Malware or virus infections that modify or delete system files to disrupt the network or install malicious redirects.
- Power outages or blackouts while the system was accessing lmhosts.sam, causing data corruption.
- System locks or bad sectors on the main disk that affect the area where the file was located.
When a component of this type fails , messages such as "Cannot register lmhosts.sam", "Cannot find lmhosts.sam in C:\Windows\Temp\", or notifications that an application cannot start because a required component is missing, may appear.
To prevent and detect these types of incidentsIt is essential to keep your antivirus software updated, perform regular scans, and monitor disk health. If errors persist, consider performing a system file check (for example, with sfc /scannow) or reinstall the application that reports the missing lmhosts.sam.
How to edit Hosts or LMHOSTS with administrator privileges
In older versions like Windows XP, modifying the hosts file was much more straightforward.Previously, you could simply open it in Notepad and save the changes. However, starting with Windows Vista, 7, 8, 10, and their server equivalents, security has been tightened, and you cannot write to it without running the editor "as administrator." C:\Windows\System32\drivers\etc.
The easiest way to overcome this obstacle is to launch Notepad (or another text editor) with elevated privileges and then open the file you want to edit. This avoids the typical "you do not have permission to save to this location, contact your administrator" errors.
Basic steps to open Hosts or LMHOSTS as administrator in Windows :
- Open Notepad with elevated privilegesGo to the Start menu, search for "Notepad", right-click on the icon and choose "Run as administrator". Accept the User Account Control (UAC) prompt and, if prompted, enter administrator credentials.
- From Notepad opened as administratorGo to “File > Open” and navigate to
C:\Windows\System32\drivers\etc\If you don't see the hosts or lmhosts file, change the "Type" filter to "All files (*.*)". - Select the file (hosts or lmhosts)Make the necessary changes and save directly from the "File > Save" menu. Since it's running with elevated privileges, Notepad will be able to overwrite the file without any issues.
After modifying the file, it's advisable to refresh the system's DNS resolution . To do this, you can open a command prompt window (also as administrator) and run:
ipconfig /flushdns
This simple command clears the DNS cache , so Windows stops using old entries and starts using what you've defined in the hosts file. Restarting your computer usually has the same effect.
How the Hosts file works and why you should modify it
In practice, the hosts file allows you to take control of name resolution on your own computer. Whenever Windows attempts to connect using a hostname, it first checks this file; if it finds a match, it completely bypasses the configured DNS servers and uses the IP address you've specified.
By modifying the hosts fileThis allows your machine to "look" directly at the IP address you define. For example, if you want to miwebsite.com resolve to the IP 1.2.3.4.5You would add a line like this:
1.2.3.4.5 miwebsite.com
From that moment on, in that specific teamevery time you try to open miwebsite.com you will go to 1.2.3.4.5Regardless of what the public DNS says. It's a very useful local override for migration testing, website debugging, or occasional access to internal servers.
Common uses of the hosts file in Windows 10 include :
- Testing a website on a new server before changing the actual DNS records, pointing the domain to the new IP only from your computer.
- Continue working while the DNS propagatescausing your computer to ignore old records.
- Block specific websites (social networks, inappropriate content pages, malware sites) associating them with
127.0.0.1or another unused internal IP address. - Block ads or trackers in bulk, importing lists of hosts with advertising or tracking domains that redirect to a null IP.
It's also important to be aware that some programs ignore the hosts file and use their own resolution logic or DNS over HTTPS. Therefore, when editing hosts, you might find that most applications respect your changes, but certain specific software may still use the original public IP address.
How to find the IP address you need to use
For an entry in the hosts file to work , you need to know the exact IP address you want to point the domain or hostname to. If it's a website hosted by a hosting provider, you can find the IP address in their control panel.
If the website is yours and you're using a control panel similar to those used in managed hosting, you'll usually see the server or website IP address when you select the domain. This is the IP address you'll then add to your local machine's hosts file for testing.
When you need to obtain the IP address of a third-party siteYou can use the command-line tool tracertAlthough it is primarily used to diagnose connectivity problems, it also displays the final IP address of the domain you are tracing.
To use tracert in Windows 10 :
- Go to Start, type “command line” or “cmd” and open the command prompt.
- Write
tracert dominio-que-te-interesa.comand hit Enter. - Check the output: you'll see the destination IP address in brackets next to the domain name on the last hop line.
With that IP address in hand , you can now go to your computer's hosts file and add the corresponding entry, separating the IP address from the name using one or more spaces or a tab.
How to make Firefox respect the Hosts file
Mozilla Firefox on Windows behaves differently from other browsers because, by default, it can use DNS over HTTPS (DoH) . This means that name resolution requests are sent directly to a remote DNS server, encapsulated in HTTPS traffic, instead of relying on the local Windows resolution system.
With DNS over HTTPS enabled , Firefox stops checking your computer's hosts file and your local DNS settings. Therefore, even if you modify hosts to point a domain to a specific IP address, if the DoH server responds with a different, valid IP address, the browser will display the page that the internet considers "official."
If you want to continue using Firefox but need it to respect the hosts file , the solution is to disable DNS over HTTPS in the browser settings. It's a quick change, and once applied, Firefox will revert to using the Windows resolver.
Basic steps to disable DoH in Firefox :
- Open Firefox and press the Menu button (the three lines).
- Sign in Configuration and make sure you're in the category General.
- Scroll down to the section Network Configuration and click Configuration.
- Look for the option Enable DNS over HTTPS and uncheck the box.
- Click on Accept to save the changes and close the window.
From that point on, Firefox will use the Windows hosts file and DNS settings just like any other compatible browser. Your local redirects, site blocking, and migration tests will also start working in Firefox.
How to lock the Hosts file against unwanted changes
Although Windows already requires administrator privileges to modify hosts , a user with sufficient knowledge or malware with elevated privileges could still alter the file and, for example, redirect you to fake sites or unblock websites you had blocked.
If you're worried about someone tampering with your hosts file without permission (for example, staff looking to bypass social media access restrictions, or potential host hijacking attacks), you can add an extra layer of protection by marking the file as "read-only".
To block the hosts file in Windows 10 :
- Navigate to
C:\Windows\System32\drivers\etc\using File Explorer. - Locate the file hostsRight-click on it and press on Properties.
- On the General tab, check the box Read only and apply the changes.
With this setting enabled, any attempt to directly modify the file will encounter restrictions . It's not an insurmountable barrier for a highly determined attacker, but it does require additional steps and reduces the likelihood of accidental changes.
When you need to edit the file yourself , simply return to the properties, uncheck "Read only", make the relevant changes, and re-check the box if you want to maintain that extra security.
How to restore the Hosts file to its original state
After multiple tests and changes to the hosts file , you might reach a point where you're unsure which entries are still useful and which are causing problems. Or you might even suspect that the file has been compromised, for example, by malware that has added strange redirects.
Instead of deleting line by line , a very practical option is to restore the hosts file to the default content provided by Microsoft. This returns the system to a "clean state" as far as hosts are concerned and eliminates any suspicious entries at once.
To restore the Windows 10 hosts file :
- Open File Explorer and, in the address bar, type or paste
%systemroot%\system32\drivers\etc, then press Enter. - rename the file hosts current (for example, to
hosts_backup) to save it as a backup. - Create a new text file in that same folder and name it exactly hosts, without extension.
- Open that new file with Notepad and paste the sample content that Microsoft provides for a default host, something similar to:
# 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 should 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 the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
Once the content has been pasted and savedThe hosts file is once again the Windows standard. Don't forget to clear the cache again. ipconfig /flushdns or restart the computer so that applications stop using old entries.
If at any point you miss an entry you had previously defined, you can always open the backup file you renamed and review which lines you are interested in recovering.
Everything we've covered so far gives you fine-grained control over how your machine resolves names , helps you diagnose resolution problems, clean up legacy configurations (like massive, useless LMHOSTS files), and protect yourself against malicious manipulation of the hosts file. A solid understanding of how these files work and how they interact with DNS, WINS, or browsers like Firefox makes all the difference between "something isn't resolving and I don't know why" and being able to pinpoint the source of the problem in minutes.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.