If you find yourself constantly losing hours of productivity to Reddit, Facebook, or YouTube, your first instinct is probably to download a website blocker extension from the Chrome Web Store. However, extensions are inherently flawed for self-discipline: when the urge to procrastinate strikes, you can simply toggle the extension off with a single click and access the distracting site anyway.
If you want to truly block a website, you need to block it at the operating system level. By editing your computer’s built-in hosts file, you can completely cut off access to a specific URL. This method works instantly across Google Chrome, Edge, Safari, and Firefox simultaneously, and it requires enough technical effort to undo that you are far less likely to cheat during your workday.
How to Block a Website on Windows 11
To edit the hosts file on Windows, you must open the Notepad application with Administrator privileges.
- Click the Start button and type
Notepadinto the search bar. - Right-click the Notepad app in the search results and select Run as administrator. Click Yes on the security prompt.
- In Notepad, click File > Open.
- Navigate to the following exact folder path:
C:\Windows\System32\drivers\etc - When you open the
etcfolder, it will likely appear completely empty. Look at the bottom-right corner of the window, click the drop-down menu that currently says “Text Documents (*.txt)”, and change it to All Files (*.*). - You will now see a file simply named hosts. Double-click it to open it.
- Scroll to the very bottom of the document. You will see some lines starting with a hash symbol (#). Click below the last line to start a new, blank line.
- Type
127.0.0.1, press the Spacebar once, and then type the website URL you want to block (e.g.,facebook.com). - Press Enter to start a new line, and add the “www” version just to be safe:
127.0.0.1 www.facebook.com - Click File > Save. Do not use “Save As”, just standard Save.
Open Google Chrome and try to visit the website. You will immediately hit an error screen stating “This site can’t be reached”.
How to Block a Website on macOS
Mac users can achieve the exact same system-level block by using the Terminal to edit their hosts file.
- Press Command + Spacebar to open Spotlight Search, type
Terminal, and press Enter. - In the Terminal window, type the following command exactly as written and press Enter:
sudo nano /etc/hosts - Type your Mac’s administrator password and press Enter. (Note: For security reasons, the terminal will not show any characters or asterisks as you type your password. Just type it blindly and press Enter).
- The Terminal will transform into a basic text editor. Use your keyboard’s down arrow to move the cursor to the very bottom of the file (below the existing IP addresses).
- Type
127.0.0.1, press the Spacebar, and type the URL you want to block (e.g.,reddit.com). - Press Enter, and type the www version as well:
127.0.0.1 www.reddit.com - To save the file, press Control + O (the letter O, not zero), and press Enter to confirm the file name.
- Press Control + X to exit the text editor.
- Finally, you need to flush your DNS cache so your Mac recognises the change immediately. Type
sudo dscacheutil -flushcacheand press Enter.
If you ever want to unblock the website in the future, simply repeat the steps for your respective operating system, delete the line of text you added to the hosts file, and save it again.