How to manage and block distracting websites using DNS filtering and Hosts files
Summary
This guide helps you troubleshoot and resolve: How to manage and block distracting websites using DNS filtering and Hosts files. Follow the steps below to fix the issue.
Common Causes
Maintaining productivity in a home office or small business environment often requires limiting access to distracting websites. Depending on your technical skill and the level of control required, you can achieve this using DNS filtering for a network-wide approach or editing the local Hosts file for device-specific restrictions.
Quick Fix Steps
If you need a fast solution without modifying system files, we recommend using a filtered DNS service such as Cloudflare for Families or OpenDNS. This redirects your internet traffic through a server that automatically blocks known distracting or malicious domains.
- Change your network DNS settings to
1.1.1.3and1.0.0.3(Cloudflare Family). - Restart your web browser.
- Attempt to visit a restricted site to verify the block is active.
Detailed Instructions
Method 1: Using the Hosts File (Device Specific)
The Hosts file is a local text file that maps hostnames to IP addresses. By mapping a website to 127.0.0.1 (the IPv4 loopback address) or ::1 (the IPv6 loopback address), the computer will attempt to direct traffic to itself, effectively blocking the site. Please note that the Hosts file only blocks domain names; it cannot block direct connections to IP addresses.
On Windows 10 and 11
- Click the Start menu and type
Notepad. - Right-click on Notepad and select Run as administrator. This is critical; otherwise, you cannot save changes.
- In Notepad, go to File > Open.
- Navigate to the following path:
C:\Windows\System32\drivers\etc - Change the file type filter from Text Documents (*.txt) to All Files (*.*).
- Select the file named
hostsand click Open. - Before editing, save a copy of this file to your Desktop as
hosts.bak. - Scroll to the bottom of the document and add the websites you wish to block on new lines using this format:
127.0.0.1 www.facebook.com127.0.0.1 facebook.com::1 www.facebook.com
- Go to File > Save and close the application.
On macOS
sudo command.
- Open Terminal (found in Applications > Utilities).
- Type the following command and press
Enter:sudo nano /etc/hosts - Enter your administrator password when prompted (characters will not appear as you type).
- Before editing, it is recommended to create a backup via the terminal using:
sudo cp /etc/hosts /etc/hosts.bak - Use the arrow keys to scroll to the bottom of the file.
- Add the sites to block using the same format as Windows:
127.0.0.1 www.instagram.comor::1 www.instagram.com - Press
Control + Oto write the changes, thenEnterto confirm. - Press
Control + Xto exit the editor. - Flush your DNS cache by typing:
sudo killall -HUP mDNSResponder
Method 2: DNS Filtering (Network Wide)
DNS filtering is more effective for organisations as it covers all devices connected to the router, including mobile phones and tablets.
Router Configuration Examples
- Telstra: Log into the Telstra Gateway interface. Navigate to Advanced Settings > Internet > DNS Settings. Change from Automatic to Manual and enter your filtered DNS addresses.
- Netgear: Log into the router admin page. Go to Advanced > Setup > Internet Setup. Under Domain Name Server (DNS) Address, select Use These DNS Servers and enter your filtered addresses.
- TP-Link: Log into the TP-Link web interface. Navigate to Advanced > Network > WAN. Change the DNS settings from Automatic to Manual and enter the primary and secondary DNS servers.
- ASUS: Log into the ASUS router settings. Go to WAN > Internet Connection. Set WAN DNS Setting to Yes and enter your preferred DNS filtering servers.
Troubleshooting
The website is still loading
Modern browsers often cache DNS records or use "DNS over HTTPS" (DoH), which bypasses local Hosts files and router settings.
- Clear Browser Cache: In Chrome or Edge, press
Ctrl + Shift + Deleteand clear the cached images and files. - Disable Secure DNS: Go to Settings > Privacy and security > Security and toggle off Use secure DNS.
- Flush DNS (Windows): Open Command Prompt and type
ipconfig /flushdns.
macOS DNS Cache Troubleshooting
If you have edited the Hosts file on macOS and the site is still accessible, you may need to flush the DNS cache manually.
- Open Terminal.
- Type the following command and press
Enter:sudo killall -HUP mDNSResponder - If you receive a "command not found" error, try:
sudo dscacheutil -flushcache - Enter your administrator password when prompted.
- Restart your web browser to clear any internal DNS caches.
I cannot save the Hosts file
This is almost always a permissions issue. Ensure you have launched your text editor as an administrator. On Windows, you must right-click the application icon to find the Run as administrator option. On macOS, ensure you are using the sudo prefix in Terminal.
Still Having Issues?
💻 Open a Ticket