For Tech-Savvy Users: Enhance Your Online Privacy
uBlock Origin: A powerful, free, and open-source ad blocker. Note: It is no longer compatible with the latest versions of Google Chrome.
For optimal security and privacy, use multiple browsers tailored to specific tasks:
Additional Privacy Solution: Host File Blocking
To further block ads and trackers, consider using a host file-based solution. This method provides an extra layer of protection but is just one part of a multi-layered privacy strategy. Be aware that host file blocking may interfere with certain websites, such as flight aggregators, causing them to function improperly.
Custom Python Script for Host File Management
I’ve developed a Python script that simplifies host file management by combining multiple host files into a single, optimized file. The script also includes convenient features to enable or disable blocking, allowing you to bypass issues with specific websites when needed. It supports three commands:
1. Build the custom blocklist version: sudo python3 hosts_manager.py –build
2. Activate the blocklist : sudo python3 hosts_manager.py –on
3. Revert to generic clean version: sudo python3 hosts_manager.py –off
#!/usr/bin/env python3 import os import shutil import urllib.request # Configuration SOURCES = [ "https://someonewhocares.org/hosts/hosts", "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts", "https://adaway.org/hosts.txt", ] LOCALHOST_LINES = [ "127.0.0.1 localhost", "::1 localhost" ] CUSTOM_HOSTS_PATH = "/etc/hosts" GENERIC_HOSTS_PATH = "/etc/hosts.generic" BLOCKED_HOSTS_PATH = "/etc/hosts.blocked" def download_sources(): lines = set() for url in SOURCES: print(f"Downloading: {url}") try: with urllib.request.urlopen(url) as response: for raw_line in response.read().decode("utf-8", errors="ignore").splitlines(): line = raw_line.strip() if not line or line.startswith("#"): continue parts = line.split() if len(parts) >= 2 and (parts[0].startswith("127.") or parts[0] == "0.0.0.0"): lines.add(f"{parts[0]} {parts[1]}") except Exception as e: print(f"Failed to download {url}: {e}") return sorted(lines) def write_hosts_file(path, entries): with open(path, "w") as f: for line in LOCALHOST_LINES: f.write(line + "\n") f.write("\n") for entry in entries: f.write(entry + "\n") print(f"Written: {path}") def backup_original(): if not os.path.exists(GENERIC_HOSTS_PATH): print("Backing up current hosts file as generic version…") shutil.copy(CUSTOM_HOSTS_PATH, GENERIC_HOSTS_PATH) def activate_custom_hosts(): if os.path.exists(BLOCKED_HOSTS_PATH): shutil.copy(BLOCKED_HOSTS_PATH, CUSTOM_HOSTS_PATH) print("Custom blocked hosts file activated.") else: print("Blocked hosts file not found. Please run with `--build` first.") def deactivate_custom_hosts(): if os.path.exists(GENERIC_HOSTS_PATH): shutil.copy(GENERIC_HOSTS_PATH, CUSTOM_HOSTS_PATH) print("Reverted to generic hosts file.") else: print("No generic hosts backup found.") def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument("--build", action="store_true", help="Download and build blocked hosts file") parser.add_argument("--on", action="store_true", help="Activate blocked hosts") parser.add_argument("--off", action="store_true", help="Revert to generic hosts") args = parser.parse_args() if args.build: backup_original() entries = download_sources() write_hosts_file(BLOCKED_HOSTS_PATH, entries) print("Blocked hosts file built.") elif args.on: activate_custom_hosts() elif args.off: deactivate_custom_hosts() else: parser.print_help() if __name__ == "__main__": main()
My host file was on “on” and I did not even realize that ublock does not work anymore.
Need privacy consulting? Book an appointment.