The Windows Hosts file is a simple text file that maps domain names to IP addresses, functioning as a local directory for your computer’s internet activity. It allows you to override DNS settings, offering faster and more direct connections. This is particularly useful for tasks like redirecting traffic, testing server configurations, or ensuring low-latency connections – especially vital for traders using platforms like NinjaTrader.
Here’s what you need to know:
- Location: The Hosts file is located at
C:\Windows\System32\drivers\etc\hostson all modern Windows versions. - Access: You need administrator rights to edit it. Open Notepad as an administrator to make changes.
- Format: Entries follow this format:
[IP address] [domain name]. Example:192.168.1.100 example.com. - Editing Steps:
- Open the file in Notepad (run as admin).
- Add or modify entries.
- Save the file (ensure it’s saved as "hosts" without a
.txtextension).
- Apply Changes: Flush the DNS cache by running
ipconfig /flushdnsin Command Prompt (admin mode).
This file is a powerful tool for customizing your network settings, but always back up the original file before making edits to avoid potential issues.
Edit HOSTS file on Windows 11, 10 (3 methods)

Finding the Hosts File on Windows
If you’re setting up your trading environment, knowing where to find the Hosts file on your Windows system is essential. This file, stored in a specific system directory, plays a key role in managing network configurations. Let’s walk through its location and how to access it.
Where to Find the Hosts File
On all modern versions of Windows – including Windows 10, Windows 11, Windows 8, Windows 7, and Windows Vista – the Hosts file is located at:
C:\Windows\System32\drivers\etc\hosts [1].
Alternatively, you can use the %SystemRoot% environment variable, which typically points to your Windows directory. This allows you to write the path as:
%SystemRoot%\System32\drivers\etc\hosts.
Using the %SystemRoot% variable ensures the path works regardless of where your Windows directory is installed.
To access the file via File Explorer, open a new window and either type the full path directly into the address bar or navigate manually to:
C:\Windows\System32\drivers\etc.
In the etc folder, you’ll find the Hosts file. It has no file extension – just the name "hosts" [1].
How to Show Hidden Files and Extensions
If you can’t see the Hosts file, it might be hidden. Here’s how to adjust your settings in File Explorer:
- For Windows 10 and newer:
Click the View tab and check the box for Hidden items. This will reveal files and folders that are normally hidden. - For older versions like Windows 7:
Go to Organize, select Folder and search options, and open the View tab. Then choose Show hidden files, folders, and drives and click OK.
Once the file is visible, you might need to open it in Notepad. To do this, change the file type filter in the Open dialog from Text Documents (*.txt) to All Files (*.*). This ensures all files in the directory, including the Hosts file, are displayed.
Getting Ready to Edit the Hosts File
To edit the Hosts file on a Windows system, you’ll need administrator rights because it’s a protected file. This safeguard exists to ensure the file isn’t altered without proper authorization.
Why Administrator Rights Are Necessary
The Hosts file is protected by Windows to prevent unauthorized changes, particularly by malware that could redirect your network traffic to harmful sites. As Russell Smith, Editorial Director at Petri IT Knowledgebase, notes:
"The hosts file can only be edited by administrators because it is in a protected system directory" [2].
Without administrative access, you’ll encounter errors like "Access denied" or "Cannot create file" when trying to save changes. Even with the right permissions, some antivirus software may temporarily block edits to the file. In such cases, you might need to disable specific security features while making your changes.
Having administrator access ensures you can quickly and securely update your network settings. Once you’re ready, the next step is to open Notepad with the necessary permissions.
How to Open Notepad with Administrator Rights
Here’s how you can launch Notepad as an administrator:
- Press the Windows key, type "Notepad", and in the search results, right-click on Notepad.
- Select "Run as administrator."
- When the User Account Control (UAC) prompt appears, click "Yes." If prompted, enter the administrator credentials.
Once Notepad is running with administrator rights, you’ll be able to make and save changes to the Hosts file without any issues.
How to Edit the Hosts File
To make changes to the Hosts file, you’ll need to open it with Notepad running as an administrator. Once that’s set, follow the steps below to edit it properly.
Opening and Reading the Hosts File
With Notepad launched as an administrator, go to File > Open and navigate to C:\Windows\System32\drivers\etc. Make sure to set the file type filter to "All Files (.)" so the Hosts file becomes visible.
Inside the file, you’ll notice comment lines starting with a #. These provide instructions and examples of how the file works. You’ll also see default entries like 127.0.0.1 localhost and ::1 localhost (for IPv6). These are essential for your system’s normal functioning and should not be altered.
Each entry in the file follows a specific format: the IP address comes first, followed by at least one space, and then the domain name. Reviewing the existing entries can help you understand how to structure any new additions.
Adding New IP and Domain Entries
If you’re working in environments like trading platforms (e.g., NinjaTrader), it’s often necessary to map specific domains to particular IP addresses. To add new entries, simply follow the format: [IP address] [domain].
For example:
192.168.1.100 trading.example.com
To ensure proper resolution, add separate entries for both the ‘www’ and non-‘www’ versions of a domain. This way, both variations will function as intended.
If you want to temporarily disable an entry without deleting it, just add a # at the start of the line. This converts the line into a comment, allowing you to test different configurations without losing your original setup.
Saving Your Changes
After making your edits, save the file to apply your changes. Since you opened Notepad as an administrator, you can save directly by selecting File > Save or using the shortcut Ctrl+S.
It’s important to save the file with the correct encoding to avoid issues. Most editors, including Notepad, will handle this automatically, keeping the file in UTF-8 format. Ensure the file name remains "hosts" without any added extensions like ".txt".
"Don’t try to change the NTFS permissions on the hosts file to edit it as a normal user. This is a security risk and the permissions may be reset by the next Windows Update or a repair process." – Peter Hahndorf [3]
If you encounter a permissions error, double-check that Notepad is running as an administrator, then try saving again.
Once saved, your changes are written to the system. However, they won’t take effect immediately. To activate them, you’ll need to clear your DNS cache.
Making Your Changes Work
Once you’ve saved the Hosts file, the changes won’t take effect until you clear the DNS cache. This step ensures your modifications are recognized by the system and applied correctly.
Clearing the DNS Cache
Windows uses a DNS resolver cache to store recent domain name lookups. To activate your Hosts file changes immediately, you need to flush this cache. Here’s how to do it:
- Press Windows + R, type
cmd, and then press Ctrl + Shift + Enter to open the Command Prompt with administrator privileges. If prompted by User Account Control, click "Yes" to proceed. - In the Command Prompt window, type the following command and press Enter:
ipconfig /flushdns - You’ll see a confirmation message: "Successfully flushed the DNS Resolver Cache." This means all cached DNS entries have been cleared, and Windows will now use your updated Hosts file for domain resolution.
While the changes take effect immediately, some applications may require a restart to recognize the new settings. For example, if you’re using trading platforms like NinjaTrader, restart the application to ensure it picks up the updated domain mappings.
Once the cache is cleared, the next step is to verify your changes.
Testing Your Connection
To confirm that your Hosts file modifications are working, follow these steps:
- Open the Command Prompt and type:
ping [domain-name]Replace
[domain-name]with the domain you modified. For instance, if you added an entry fortrading.example.com, you would typeping trading.example.com. - The ping results will display the IP address Windows is using for that domain. If your Hosts file entry is working, the IP address shown should match what you specified in the file, not the domain’s original IP address. For example, you might see something like: "Pinging trading.example.com [192.168.1.100] with 32 bytes of data" Here, the IP address in brackets (
192.168.1.100) should match the one you entered in the Hosts file. - For additional verification, use the
nslookupcommand:nslookup [domain-name]This will confirm the IP address being resolved for the domain.
If you’re working in a trading environment, it’s especially important to test both the main domain and any subdomains you’ve configured. For example, if you’ve redirected traffic for platform connectivity or data feeds, try accessing the service through your trading software. Monitor the platform’s connection status and the reliability of data feeds to ensure the changes are improving performance without causing disruptions.
Undoing Changes to the Hosts File
Reverting changes to the Hosts file can help resolve system issues or return your configurations to default. Windows offers a few straightforward ways to restore the file to its original state.
Backing Up the Hosts File
Before making any edits, it’s always a smart move to back up the Hosts file. This ensures you can quickly restore the original settings if something goes wrong.
To create a backup:
- Navigate to
C:\Windows\System32\drivers\etc\and locate the hosts file. - Right-click the file, select Rename, and change its name to
hosts.bak. This keeps the backup in the same location for easy access. - Alternatively, you can copy the file to a different location. Right-click the file, choose Copy, and paste it somewhere safe, like your desktop, Documents folder, or even an external drive.
Once your backup is secure, you’re ready to restore the original file if needed.
Restoring the Default Hosts File
If you encounter issues or need the default configuration, here’s how to restore the original Hosts file:
- Recreating the Default File Without a Backup
If no backup exists, you can manually recreate the default file. Open Notepad with administrator privileges and paste the following default content into a new file:# 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 localhostSave this file as
hosts(without an extension) in theC:\Windows\System32\drivers\etc\directory. To avoid accidentally adding a.txtextension, select All Files in the "Save as type" dropdown menu. - Restoring from a Backup
If you’ve already backed up the file, restoring is simple. Delete or rename the current Hosts file, then rename your backup file (hosts.bak) back tohosts. This instantly reinstates the previous configuration.
After restoring the file, it’s important to clear your DNS cache. Open Command Prompt as an administrator and run the following command:
ipconfig /flushdns
If you’re still facing connectivity issues, restart your computer to ensure all cached settings are cleared.
Additional Tips for Troubleshooting
- If you continue to experience problems, temporarily disable your antivirus software while restoring the Hosts file. Some antivirus programs might block changes to this file.
- Always double-check that each line in the file follows the correct format: IP address followed by a space or tab, then the domain name. Improper formatting can cause entries to be ignored, potentially disrupting connectivity.
Conclusion: Key Points for Traders
Gaining a solid understanding of the Windows Hosts file can give futures traders an edge by fine-tuning their trading setup. By using local DNS overrides, you can direct your NinjaTrader platform to the most efficient servers, cutting out DNS delays and boosting both speed and reliability.
To edit the Hosts file, you’ll need administrator rights. This safeguard ensures that changes are intentional, but it also means you must always run your text editor as an administrator to make adjustments.
Accuracy is crucial – incorrect syntax can cause major connectivity problems, especially during busy trading hours. Each entry should follow this format: the IP address, at least one space, and the corresponding domain name. Double-checking this step can save you from unnecessary headaches.
For TraderVPS users, these tweaks can further enhance the platform’s ultra-low latency performance. Whether you’re routing traffic to nearby servers or ensuring stable access to your broker’s data feeds, local DNS overrides can be a key part of a reliable trading environment. But reliability also depends on protecting your original settings.
Backing up your Hosts file is a must. It allows you to quickly revert to the original configuration if something goes wrong, minimizing downtime in fast-paced markets.
Once your changes are complete, don’t forget to flush the DNS cache and test your connections before diving into live trading. Spending a few extra minutes on these final checks can help you avoid costly disruptions during critical trading moments.
FAQs
Why should I back up the Hosts file before editing it, and how can I securely save the backup?
Before making any changes to the Hosts file, it’s essential to back it up. Why? Because having a backup ensures you can quickly restore the original settings if something goes wrong – like connectivity problems or accidental misconfigurations. Without it, troubleshooting can turn into a real headache.
Creating a backup is straightforward. Just copy the Hosts file and save it in a secure location, such as a specific folder on your computer or an external drive. Be sure to store it somewhere safe where it won’t be accidentally altered or deleted, so it’s readily available if you need it.
What problems can occur if the Hosts file is modified incorrectly, and how can I fix them?
Incorrect modifications to the Hosts file can lead to problems like websites failing to load, being redirected to incorrect IP addresses, or general network connectivity issues. To address these problems, here’s what you should do:
- Open the Hosts file with administrator privileges to ensure you can make changes.
- Carefully review the syntax of each entry. Every line should follow this format:
IP address(space)domain name. - Clear the DNS cache by opening the Command Prompt and running this command:
ipconfig /flushdns.
If the issue continues, consider restoring the original Hosts file or checking for errors in recent edits. Always back up the file before making any changes to prevent further complications.
How does editing the Hosts file enhance my trading platform, and how can I confirm the changes are effective?
Editing the Hosts file can give you more control over how specific domain names are resolved, which can directly benefit your trading platform. By tweaking this file, you might see faster connection speeds, resolve domain-related problems, and enjoy a smoother overall platform experience – key advantages in a high-stakes trading environment.
After making changes to the Hosts file, it’s a good idea to test your platform’s connectivity and performance. Check for noticeable improvements in response times, enhanced stability, or resolution of any earlier issues to confirm that the adjustments are having the desired effect.






