Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversUpgrade WatchAmazon USWireless earbuds and case options for outdoor-to-indoor season shiftSweat-resistant and noise-isolating picks as workouts move indoors.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
THEGEEKSCLUB

How to Block Websites on Windows Using Hosts File

Learn how to block websites on any Windows PC by editing the hosts file. A simple, free, step-by-step guide to improve focus and enhance security.

How to Block Websites on Windows Using Hosts File
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Want a free and effective way to block distracting websites on your Windows computer? Whether you’re aiming for better productivity or trying to keep your family safe online, editing the Windows hosts file is a powerful tool built right into your operating system. This method works universally across all web browsers on your PC without needing any extra software. This guide will walk you through every step of the process, from finding the hosts file to making sure your changes take effect immediately.

What is the Hosts File and How Does It Block Websites?

Before a web browser connects to a website, Windows first checks the hosts file. The hosts file is a simple text document that can act as a local address book for website domains. You can manually create entries in this file to tell your computer where to go—or where not to go—when it tries to access a certain domain.

To block a website, we simply tell the hosts file to redirect that website’s address (like www.facebook.com) to a non-existent or internal IP address on your own computer. When your browser tries to connect, it gets sent to this dead end, and the website fails to load. It’s a surprisingly simple and effective trick.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Shopping ad
Sale
FYY Electronic Organizer, Travel Tech Pouch Bag, Cable Organizer Black
  • Dimensions: 7.5" x 4.3" x 2.2". Compact size and lightweight make it easy to carry and put into your backpack, handbags or laptop bag without taking much space. Suitable for family use and daily organization. Note: Small mesh pockets are ideal for charging cords no longer than 3ft; longer cables (over 3ft) fit better in the larger compartments
  • Quality Material: This electronic organizer travel case made of high quality durable waterproof oxford and soft sponge inside to secure your gadgets in place and deliver a quick access whenever you want. Water-resistant fabric protects your gear from unexpected splashes, keeping all your electronic essentials safe and secure
  • Double Layers Design: This tech pouch features a double-layer interior design with 8 compartments, including multiple see-through mesh pockets and ample space to store your cords, cables, USB drives, cellphone, charger, mouse, flash drive and more, keeping all accessories neatly organized and tangle-free
  • Practical and Convenient: Comes with a comfortable hand strap for easy carrying; You may carry it in your hand when heading out. Durable and smooth zipper closure keeps your favorite device securely, convenient for you to have quick access to the items inside the case
  • Portable and Lightweight: The small size and lightweight design durable cable organizer pouch is a perfect choice when going on holiday, business trip, travel, office. Enjoy hassle-free travel without wasting time on tangled accessories. Great gift for yourself also a nice share with families and friends. (No include cords, electronic accessories)

Step-by-Step Guide to Blocking a Website

The process involves running Notepad with administrative rights, opening the hosts file, adding the websites you want to block, and then saving the file. Let’s break it down.

Step 1: Open Notepad as an Administrator

This is the most important step. The hosts file is a protected system file, so you need administrative privileges to edit it. If you try to open and save it normally, you will get a “permission denied” error.

  1. Click the Start button or press the Windows key.
  2. Type “Notepad” into the search bar.
  3. In the search results, right-click on Notepad and select Run as administrator.
  4. A User Account Control (UAC) prompt will appear. Click Yes to grant administrative permissions.

You will now have a blank Notepad window open, but this instance of Notepad has the power to edit system files.

Shopping ad
Ordilend Keyboard Cleaner & Laptop Cleaning Kit, All-in-1 for Computer PC
  • 【UPGRADED LAPTOP CLEANING KIT 】 The macbook cleaning kit computer screen cleaner comes with a number of accessories including a retractable large brush, polishing cleaning cloth X 2, keycap puller, metal pen tip, flocking sponge, thin soft brush, soft plastic lens cleaning pen, 5 replacing cloth, large cleaning microfiber cloth. You deserve the comprehensive computer cleaning kit keyboard vacuum at a low cost
  • 【PROFESSIONAL KEYBOARD CLEANING KIT】 The laptop screen cleaner keyboard cleaner can pull out the keycaps of gaming keyboards and mechanical keyboards. A retractable keyboard brush works on laptops and keyboards, while the mini high-density brush is great for deep cleaning between keys for cleaning between flatter keys on a laptop, the metal pin tip gently removes any stains. This electronic cleaning kit macbook cleaner totally meets professional cleaning needs
  • 【OFFICE DESK ACCESSORIES】This keyboard cleaner kit is easy to use and can clean your keyboard and electronic screen with just one swipe. Wiping with the 2mm thicken widen polishing cleaning cloth designed at a right angle for better fitting screen corners of computers with our recyclable cleaning spray, The laptop cleaner kit for macbook effectively absorbs stubborn stains, leaves no discoloration, no streaks, and no fiber shedding on the screens
  • 【MULTIFUNCTIONAL TOOLS 】Mini soft brush and soft plastic lens cleaning pen are specially designed for DSLR camera screen, lens, and other delicate surfaces. 5 more cleaning cloths of it supplied for replacement. The flocking sponge is an excellent tool for cleaning earbuds charging cases, And the earbud cleaning kit is ideal. This electronics for college students is equivalent to 10 other electronic cleaning kit
  • 【PORTABLE DESIGN & CLEANER TOOL】 The office supplies is compact in design, easy to carry, and you can easily take it anywhere. It's convenient to keep one in a drawer, one in your car, or in your bag and dorm. It is easy to use and can clean your keyboard and electronic screen with just one swipe. Is the college essentials cleaning tool for your friends, family, colleagues and students

(Note: An illustrative image would be placed here in a live article)

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 2: Open the Hosts File

Now that Notepad is running with the correct permissions, you need to navigate to the hosts file’s location.

  1. In Notepad, click File > Open.
  2. In the “File name” box, paste the following path and press Enter:
  3. C:\Windows\System32\drivers\etc
  4. By default, you won’t see any files because Notepad is looking for .txt files. Click the dropdown menu in the bottom-right corner that says “Text Documents (*.txt)” and change it to “All Files (.)”.
  5. You will now see several files. Select the file named “hosts” and click Open.

(Note: An illustrative image would be placed here in a live article)

Shopping ad
Sale
BAGSMART Large Electronic Organizer Travel Case for Tech Accessories, Black
  • Compatible Space: This electronics organizer bag features 2 zippered mesh pockets fits phones, standard power banks, 4 elastic loop pouches for small items, 2 elastic loop pouches for wireless headphones and small chargers. Elastic loops for phone charging cable. And specific slots for SD cards. Please check the size to ensure it meets your needs
  • Lightweight Travel Accessories: The size of the electronic organizer travel case is 10.6" L x 7.5" W x 1.2" H, Compact but substantial size fits your intended bag or space. Suitable for traveling use and daily organization
  • Keep Everything Organized: This compact travel organizer features dedicated compartments for your phone charger, cables, and tech accessories, keeping them tangle-free and ready to go. You can find travel accessories quickly, no chasing cords in your pack anymore
  • Durable Travel Essentials: Features double zippers for easy access, elastic loops with non-slip grips for daily protection. Organizer for office use and traveling, (Not including cords, electronic accessories). It can serve as a travel checklist. Before you leave a place, just open the case and check if everything is there, preventing you from leaving things behind
  • Versatile Use: Its practicality and convenience make it a travel essential bag. It is suitable for a weekend trip, business trip, and travel. This organizer pouch is suitable for office, business, daily use and can be given as a gift for friends, family, or men, for birthdays, Valentine's Day, Christmas Day, Father's Day

Step 3: Add Websites to the Block List

The hosts file will open, showing some text that explains its purpose. Any line that starts with a # symbol is a comment and is ignored by Windows.

To block a website, you will add a new line at the very end of the file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Go to the bottom of the file and start a new line.
  2. Type 127.0.0.1, press the Tab key or a few spaces, and then type the website address you want to block.
  3. For best results, you should block both the www and non-www versions of the site. Create a separate entry for each.

The IP address 127.0.0.1 is the “localhost” or “loopback” address. It’s your own computer’s internal IP address. By pointing a website’s domain to this address, you prevent your computer from reaching the actual site on the internet.

Shopping ad
Sale
ColorCoral Cleaning Gel Universal Dust Cleaner for PC Keyboard Car Detailing Office Electronics Laptop Dusting Kit Computer Dust Remover, Computer Gaming Car Accessories, Gift for Men Women 160g
  • Universal fit: ColorCoral cleaning gel, simple and convenient cleaning kits for PC/laptop keyboard and other rugged surface, such as the car vent, camera, printer, telephone, calculator, Instrument, speaker, air conditioner, TV and other appliances
  • Safe cleaning gel: The keyboard cleaner gel is made from natural gel, no sticky to hands, smells sweet with lemon fragrance, no stimulation to skin
  • Easy dust cleaning: Make sure your hands are dry and clean, knead the cleaning gel into a ball, press the cleaning gel slowly into the keyboard, car vent and rugged surface till the cleaning gel could touch the bottom and then pull out, the dust would be carried away with the cleaning gel
  • Reusable: The keyboard cleaning gel could be used repeatedly till the color turn to dark or it become sticky, then you have to replace the cleaning gel with a new one. After cleaning, please stock the cleaning gel in cool place. (Note: Don’t wash the gel in water.)
  • In the package: 1 can of universal cleaning gel, we provide the cleaning gel with brand new, if you find the package broken, the cleaning gel dirty, or any other quality issues, please email us through message, we provide you new one soon

Example Block List:

To block Facebook and Twitter, you would add the following lines to the end of your hosts file:

# Block distracting social media sites

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

127.0.0.1       www.instagram.com

127.0.0.1       instagram.com

Step 4: Save Your Changes

Once you’ve added the websites you want to block, you need to save the file.

  1. Click File > Save.
  2. Close Notepad.

Since you opened Notepad as an administrator, it will save without any permission errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Shopping ad
Sale
HOTO Pocket-Size Laser Measuring Tool, EDC Gadget Birthday Gift for Men Dad
  • Award-Winning Compact Design & EDC-Ready Gift Choice: Weighing only 0.09 lb and sized like a credit card, this compact laser measure is designed for everyday carry. It slips easily into a pocket, tool pouch, or bag, and can attach to a keychain for quick access wherever you go. Its minimalist design, premium tactile finish, and practical one-button measuring make it a useful EDC gadget for DIYers, real estate agents, homeowners, and tech enthusiasts. A thoughtful gift for men on any occasion
  • One-Button Easy Measuring, Simple to Use: Designed with simple one-button operation, this compact laser tape measure makes quick measuring easy without complicated controls. Just press to measure room dimensions, furniture spacing, window height, wall décor placement, and everyday distances around the home. Ideal for users who want a smart, pocket-size measuring tool that fits naturally into an everyday carry (EDC) setup and feels intuitive, modern, and easy to use
  • Fast & Accurate Indoor Measurements with Class 2 Laser: Measure distances from 0.16 ft to 98 ft with up to ±1/16 in / ±2 mm accuracy. With quick measurement response in about 0.2 seconds, HOTO helps you check spaces efficiently for home renovation, furniture layout, moving, decorating, craft projects, and DIY planning. Built with a Class 2 laser for everyday indoor measuring; use as directed and avoid direct eye exposure
  • Low-Power OLED Display & USB-C Rechargeable Convenience: The low-power OLED display provides clear indoor readings while helping reduce battery drain. With USB-C rechargeable design, auto shut-off, and up to 1000 measurements per charge, this digital laser measure is built for repeated daily use without frequent battery replacement. Compact enough to keep in a drawer, toolbox, bag, or pocket
  • Useful for Home, Work & Everyday Projects: From home renovation and furniture measuring to room planning, real estate checks, interior design, and light construction projects, this pocket-size laser distance measure is made for practical everyday use. Compact enough to keep in a drawer, toolbox, bag, or pocket, it is a stylish measuring tool that feels just as giftable as it is useful

Step 5: Flush the DNS Cache (Important)

Windows keeps a cache of recently visited websites to speed up Browse. To make sure your changes to the hosts file take effect immediately, you need to clear this cache.

  1. Open the Command Prompt as an administrator (just like you did for Notepad in Step 1).
  2. Type the following command and press Enter:

DOS

ipconfig /flushdns

  1. You will see a confirmation message: Successfully flushed the DNS Resolver Cache.

This command forces Windows to reread the hosts file for any future website requests.

How to Test and Unblock Websites

Testing: To test if the block is working, simply open any web browser and try to navigate to one of the websites you added to the hosts file. You should see an error page saying the “site can’t be reached” or something similar.

Unblocking: To unblock a website, simply follow the same steps to open the hosts file as an administrator and either:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Delete the lines you added.
  • Or, place a # symbol at the beginning of each line to turn it into a comment, which makes Windows ignore it. This is a good way to temporarily unblock a site without having to re-type the line later.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi
Ankit Gupta
Written by

Ankit Gupta

Ankit Gupta is an Engineering graduate and an MBA post graduate. He brings with himself 5 years plus global writing experience on technology, travel, finance and medical. He follows technological developments especially Microsoft. Also, he has a deep liking for wild life and travels to various wildlife conservatories to be with the nature.

More from this author ↗
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.