Blocking websites on Windows using the hosts file
Do you want to block access to certain websites on your Windows computer? Whether it’s to minimize distractions while working or restrict access for children, Windows offers a built-in method to do this without additional software. The key is a small system file called hosts.
This article will guide you through the process step by step.
What is the hosts file?
The hosts file is a simple text file used by the operating system to directly map domain names (like www.google.com) to an IP address.
When you type a website into your browser, Windows checks this file first before contacting a public DNS (Domain Name System) server. We can exploit this by redirecting an unwanted domain to an incorrect or invalid IP address—usually your own computer (the “localhost”).

Step-by-step instructions for blocking
To edit the hosts file, you need administrator privileges. This is the most common stumbling block.
Step 1: Open the editor as administrator
You can’t simply open and save the file by double-clicking it. You must explicitly start your text editor (e.g., Notepad/Editor) with elevated privileges.
Step 1: Open the editor as administrator
…
- Press the Windows key.
- Type “Editor” or “Notepad”.
- Right-click the “Editor” icon in the search results.
- Select “Run as administrator”.
- Confirm the User Account Control (UAC) prompt with “Yes”.
Step 2: Find and open the “hosts” file
- In Editor (run as administrator), click File > Open….
- Navigate to the following folder. The easiest way is to copy the path directly into the address bar of the “Open” dialog: C:\Windows\System32\drivers\etc
- By default, you won’t see any files, as Editor only looks for .txt files. In the dialog box, change the setting from “Text files (.txt)” to **”All files (.*)”** in the bottom right corner.
- You should now see a file called hosts. Select it and click “Open”.
Step 3: Enter the websites to be blocked
- You will now see the contents of the hosts file. Most of it consists of comments that begin with a # symbol.
- Scroll to the very end of the file.
- To block a website, add a new line. The rule is: first the IP address to which the website will be redirected, then (separated by a space or a tab) the domain name.
- We are using the IP address 127.0.0.1. This is the “loopback” address, which always points to your own computer. Since no website under this domain is running on your computer, the request will fail (the page cannot be loaded).
Example: To block Facebook and Twitter, add the following lines to the end:
#Blocking Distractions
127.0.0.1 www.facebook.com
127.0.0.1 facebook.com
127.0.0.1 www.twitter.com
127.0.0.1 twitter.com
Important: It is advisable to always enter both the version with www. and the version without www. to ensure that both are blocked.
Step 4: Save and Close
- Click File > Save. (If you receive an “Access denied” error message, you did not start the editor as administrator as in Step 1.)
- Close the editor.
Step 5: Apply Changes (Optional, but recommended)
To ensure the changes take effect immediately, you should clear your system’s DNS cache. Otherwise, your PC might still “remember” the old, correct IP address.
- Press the Windows key and type “cmd”.
- Right-click on “Command Prompt” and select “Run as administrator”.
- Type the following command and press Enter: ipconfig /flushdns
You should receive a success message.
If you now try to open www.facebook.com in any browser (Chrome, Firefox, Edge, etc.), the page should no longer load.
Important Notes
- Administrator privileges: The most important thing is that editing and saving the hosts file only works with administrator privileges.
- Antivirus software: Some antivirus programs or security suites monitor the hosts file to prevent malicious software from modifying it. Your antivirus program may block the change or warn you. In this case, you may need to explicitly allow the change in your antivirus program.
- Syntax: Do not use a # at the beginning of a line you want to add, as this makes the line a comment and it will be ignored.
- Undoing: To restore access, simply reopen the hosts file (as administrator), delete the added lines, and save the file.
“`
Conclusion
Editing the hosts file is a quick, free, and system-wide method to control access to specific websites. It works in all browsers and for all users of the computer and is very effective if the steps are followed precisely.
Beliebte Beiträge
The Great Feast: Who will survive the streaming war?
The streaming market is imploding. Services like Paramount+ are fighting for survival, and Disney is posting billions in losses. Is a major wave of mergers imminent? What will happen to our content and subscriptions when the consolidation begins?
10 signs that it’s time for a new job!
Dissatisfied with your job? This article reveals 10 clear signs that a job change might be necessary. If the Sunday blues become chronic, you're no longer learning anything, or you lack appreciation, it's time to be honest with yourself. A guide to making your career decision.
Salary negotiation: 5 phrases that can get you up to 15% more
Want a 15% raise? A successful salary negotiation depends on preparation and the right words. We'll show you five phrases you need to use – from setting the anchor to responding to a "no." This is how you argue persuasively.
Die besten Live-Übersetzer-Earbuds im Check
Schluss mit Sprachbarrieren! Moderne Earbuds wie Google Pixel Buds & Timekettle übersetzen Gespräche live. Wir zeigen die besten Modelle, erklären die KI-Technik, nennen die Kosten und zeigen, wo die Technologie noch an ihre Grenzen stößt.
So sieht das wirklich perfekte Homeoffice-Setup für 2026 aus
Ihr Homeoffice ist veraltet? Steigern Sie 2026 Produktivität & Gesundheit. Unser Guide zeigt das perfekte Setup: von ergonomischen Stühlen und 4K-Webcams bis zu Mesh-WLAN und Kabelmanagement. So investieren Sie in Ihre Karriere.
Internet, Telefon & TV: Die besten Komplettpakete
Internet, TV & Telefon aus einer Hand? Wir vergleichen die Komplettpakete von Telekom, Vodafone, O2 & 1&1. Wer punktet bei Speed, TV-Komfort (MagentaTV vs. GigaTV) und Preis? So finden Sie das beste Triple-Play-Angebot für Ihre Adresse.

























