Block Ads on Any Linux Browser: Step-by-Step
In this article
This guide shows you how to block ads on any web browser in Linux using system-wide DNS filtering and per-browser extensions. You'll get a cleaner, faster browsing experience without manually configuring each browser. The methods work on Firefox, Chrome, Chromium, Brave, and others.
What You'll Need
- A Linux system with sudo access (for system-wide DNS blocking)
- An internet connection
- Your browser's extension manager (for the per-browser method)
Step-by-Step
- Choose your approach. You have two main options: (1) a browser extension that blocks ads only in that browser, or (2) a system-wide DNS filter that blocks ads on all browsers and apps. For most users, a browser extension is simpler; for whole-system protection, use DNS filtering.
- Install a browser extension (per-browser method). Open your browser's extension store (e.g., Chrome Web Store, Firefox Add-ons, or the Brave extensions page). Search for a reputable ad blocker like uBlock Origin or AdGuard. Click "Add to Browser" and confirm any permissions. The extension will start blocking ads immediately.
- Configure the extension (optional but recommended). Click the extension's icon in the toolbar. Open its settings. Enable "Annoyances" filters (cookie banners, popups) if available. For uBlock Origin, go to the dashboard, select "Filter lists," and tick additional lists like "EasyList + EasyPrivacy" (usually enabled by default).
- Test the extension. Visit a site known for heavy ads (e.g., a news site). You should see fewer banners and no video ads. If ads still appear, check that the extension isn't paused for that site.
- Set up system-wide DNS filtering (alternative or extra). Open a terminal. Edit the DNS resolver configuration file:
sudo nano /etc/resolv.conf. Replace the existing nameserver lines with a DNS server that filters ads, likenameserver 94.140.14.14(AdGuard DNS) ornameserver 1.1.1.2(Cloudflare with malware blocking, but not ad blocking—use AdGuard or NextDNS for ads). Save the file. This will affect all browsers and apps that use the system DNS. - Make DNS changes permanent. The
resolv.conffile may be overwritten by NetworkManager. To prevent this, edit/etc/NetworkManager/NetworkManager.confand add under[main]:dns=default. Then restart NetworkManager:sudo systemctl restart NetworkManager. Alternatively, use a tool likeresolvconfor set static DNS in your network connection settings via your desktop environment's network manager GUI. - Flush DNS cache. After changing DNS, clear existing cached entries:
sudo systemd-resolve --flush-caches(if using systemd-resolved) orsudo killall -HUP dnsmasq(if using dnsmasq). Then restart your browser. - Verify system-wide blocking. Visit a site with ads. You should see fewer ads across all browsers. If not, check that your DNS changes took effect by running
dig example.comand seeing the correct resolver IP.
Common Mistakes
- Editing resolv.conf incorrectly. Make sure you use a valid DNS server IP. A typo will break all internet access.
- Forgetting to make DNS changes permanent. If you only edit resolv.conf, your changes may revert after reboot or network reconnect.
- Installing multiple ad blockers. Running two ad blockers at once can slow down browsing and cause conflicts. Stick to one.
- Disabling the blocker for a site. Many blockers have a "pause on this site" option. If you accidentally enable it, ads will appear on that site.
- Using a DNS server that doesn't block ads. Cloudflare's 1.1.1.1 does not block ads; it only provides malware protection. Use AdGuard (94.140.14.14) or NextDNS (you need to set up an account).
Tips
- Use uBlock Origin specifically. It is open-source, lightweight, and widely regarded as the most effective and least resource-hungry blocker.
- Enable additional filter lists. In uBlock Origin, go to settings > filter lists and enable regional lists if you browse non-English sites.
- Whitelist sites you trust. If a site breaks (e.g., videos don't load), you can allow ads on that site by clicking the blocker's icon and toggling the power button for that site.
- Use a hosts file for extra blocking. Some users prefer to add ad domains to
/etc/hosts. This is more manual but works system-wide without DNS changes. You can download a pre-made hosts file from sites like StevenBlack's GitHub (but verify the source). - For Firefox, consider using the built-in tracking protection. Go to Settings > Privacy & Security and set "Strict" mode. This blocks many trackers and some ads.
Troubleshooting
- Ads still appear after installing an extension. First, check that the extension is enabled (not paused). Then, try disabling other extensions that might conflict. Also, some sites use anti-adblock scripts; the blocker may need a filter list update. Click the extension icon and select "Update now" if available.
- Internet stops working after DNS change. You likely entered a wrong DNS server IP. Edit
/etc/resolv.confagain and put a known-good DNS likenameserver 8.8.8.8(Google) to restore connectivity. Then correct your chosen DNS. - DNS changes revert after reboot. This is common with NetworkManager. Follow step 6 to make changes permanent. If you're using a different network manager, check its documentation for setting DNS.
- Some sites break (videos won't play, forms don't submit). The ad blocker may be blocking necessary scripts. Whitelist the site or temporarily disable the blocker. In uBlock Origin, click the icon and toggle the large power button to turn off blocking for that site.
- System-wide DNS blocking doesn't work in browsers that use DoH (DNS over HTTPS). Firefox and Chrome may have "Secure DNS" enabled, which bypasses system DNS. In Firefox: Settings > General > Network Settings > Enable DNS over HTTPS (uncheck). In Chrome: Settings > Privacy and Security > Security > Use secure DNS (turn off).
- Ads appear in apps outside the browser. System-wide DNS filtering should block them, but some apps use hardcoded IPs. In that case, only a hosts file or a firewall rule can help, which is beyond this guide.
Frequently Asked Questions
Does blocking ads slow down my browser?
No, it usually speeds it up because fewer resources are used to load ads. A well-coded blocker like uBlock Origin has minimal overhead.
Will ad blocking work on YouTube?
Yes, most ad blockers block video ads on YouTube. However, YouTube occasionally changes its code, and you may need to update your filter lists.
Is it legal to block ads?
Yes, blocking ads is legal in most countries. It's your device and your network traffic. Some websites may have terms of service that prohibit ad blocking, but that's a civil matter, not a criminal one.
Can I block ads on a browser that doesn't support extensions?
Yes, use the system-wide DNS method. It works for any browser that uses the system's DNS settings, which is most of them.
Will blocking ads break websites?
Occasionally, a website may rely on scripts that are also used for ads. If something breaks, whitelist that site. This is rare with modern blockers.
What's the difference between a browser extension and DNS filtering?
A browser extension blocks ads at the page level, removing elements and blocking requests. DNS filtering blocks the domain names of ad servers, preventing the browser from even connecting to them. DNS filtering is broader but less precise.