{"id":48258,"date":"2025-03-03T15:06:27","date_gmt":"2025-03-03T15:06:27","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=48258"},"modified":"2025-03-23T11:16:51","modified_gmt":"2025-03-23T11:16:51","slug":"block-ads-trackers-system-wide-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2025\/03\/block-ads-trackers-system-wide-ubuntu\/","title":{"rendered":"Block Ads &#038; Trackers System-wide in Ubuntu Linux using hBlock"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-48259\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This tutorial shows how to block ads, trackers, and malware domains system-wide in Ubuntu and other Linux desktop using hBlock.<\/p>\n<p>hBlock is a free open-source script that collects a large list of domains that serve ads, tracking scripts and malware from multiple sources. It blocks them by mapping all those domain names to 0.0.0.0 using <code>hosts<\/code> file, thus it works system-wide.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48260\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks-700x467.webp\" alt=\"\" width=\"610\" height=\"407\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks-700x467.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks-300x200.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks-768x512.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hosts-blocks.webp 1035w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p><b>NOTE 1: Disable ads may hurt the websites that you prefer, as many sites rely on displaying ads to keep alive.<\/b><\/p>\n<p><b>NOTE 2: Without installing hBlock, advanced users may visit <a href=\"https:\/\/hblock.molinero.dev\/\" target=\"_blank\" rel=\"noopener\">its website<\/a> to get the latest list of ads domains and block by manually editing the hosts file.<\/b><\/p>\n<h3>Step 1: Install hBlock<\/h3>\n<p>To get hBlock, press <code>Ctrl+Alt+T<\/code> to open up a terminal window, then run command to install the curl tool:<\/p>\n<pre>sudo apt install curl<\/pre>\n<p>Then copy and paste the whole commands below and run as single:<\/p>\n<pre>curl -o \/tmp\/hblock 'https:\/\/raw.githubusercontent.com\/hectorm\/hblock\/v3.5.0\/hblock' \\\r\n  &amp;&amp; echo 'bb8f632fcb101ea017fb00a8d02925dfc7d5a6d075e2cb30e4bc293e5c0628b1  \/tmp\/hblock' | shasum -c \\\r\n  &amp;&amp; sudo mv \/tmp\/hblock \/usr\/local\/bin\/hblock \\\r\n  &amp;&amp; sudo chown 0:0 \/usr\/local\/bin\/hblock \\\r\n  &amp;&amp; sudo chmod 755 \/usr\/local\/bin\/hblock<\/pre>\n<p>The commands will first using <code>curl<\/code> to download the script from Github, then verify file integrity, install (move) to <code>\/usr\/local\/bin<\/code> directory, set the ownership and read\/read\/executable permissions.<\/p>\n<p>The <code>sudo<\/code> command requires user authentication, you need to type password (no asterisk feedback) when it&#8217;s blinking at &#8220;[sudo] password for USER&#8221;.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/get-hblock.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48261\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/get-hblock-700x373.webp\" alt=\"\" width=\"610\" height=\"325\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/get-hblock-700x373.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/get-hblock-300x160.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/get-hblock.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>As time goes by, the project may release newer versions when you see this tutorial. You may go to the <a href=\"https:\/\/github.com\/hectorm\/hblock\" target=\"_blank\" rel=\"noopener\">project website<\/a> if the command above is outdated.<\/p>\n<h3>Step 2: Block \/ Unblock Ads and Trackers<\/h3>\n<p>Before start using hBlock, it&#8217;s better to backup the <code>\/etc\/hosts<\/code> first if you have custom settings there. To do so, run command:<\/p>\n<pre>sudo cp \/etc\/hosts \/etc\/hosts.backup<\/pre>\n<p><b>To start blocking ads and trackers<\/b>, simply run the command below in terminal:<\/p>\n<pre>hblock<\/pre>\n<p>It will start downloading list of ads domains and tracking scripts from Github and apply to block them. As it will make changes to &#8216;\/etc\/hosts&#8217; file, you need to type user password (when it asks) to grant permission.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48262\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run-700x540.webp\" alt=\"\" width=\"610\" height=\"471\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run-700x540.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run-300x232.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run-768x593.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-run.webp 946w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>If everything goes well, you may now open any website in web-browser or any app that contain advertisements to if it works!<\/p>\n<p><b>To temporarily disable hBlock<\/b>, use command:<\/p>\n<pre>hblock -S none -D none<\/pre>\n<p>And, you may re-run <code>hblock<\/code> to start it again.<\/p>\n<p>For choice, user may create and add domain names into <code>~\/.config\/hblock\/allow.list<\/code> file (create if not exist) to unblock certain domains. For more about how to use the script, run <code>hblock --help<\/code>.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-help.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48263\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-help-700x505.webp\" alt=\"\" width=\"610\" height=\"440\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-help-700x505.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-help-300x216.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/hblock-help.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Add Toggle button to Turn ON\/OFF hBlock (GNOME only)<\/h3>\n<p>Some websites or apps may refuse to work well with ads disabled. Without running the command above again and again, GNOME users may install an extension to add a toggle button in top-right Quick Settings menu.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-quickmenu.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-48264\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-quickmenu.webp\" alt=\"\" width=\"449\" height=\"477\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-quickmenu.webp 449w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-quickmenu-282x300.webp 282w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><\/a><\/p>\n<p><b>NOTE: The Extension so far only works in GNOME 45\/46\/47, meaning for Ubuntu 24.04\/24.10, recent Fedora Workstation, etc distributions.<\/b><\/p>\n<p>For Ubuntu, first search for &amp; install &#8220;Extension Manager&#8221; from App Center (filter by Debian package).<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48234\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager-700x409.webp\" alt=\"\" width=\"610\" height=\"356\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager-700x409.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager-300x175.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager-768x449.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/02\/install-extensionmanager.webp 1116w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Then, launch the tool and navigate to &#8220;Browser&#8221; tab. Finally, search then install &#8220;Blocker&#8221; extension.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48265\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension-700x458.webp\" alt=\"\" width=\"610\" height=\"399\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension-700x458.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension-300x196.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension-768x502.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-extension.webp 1002w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Or, open the extension page in EGO:<\/p>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background\" href=\"https:\/\/extensions.gnome.org\/extension\/7831\/blocker\/\" target=\"_blank\" rel=\"noreferrer noopener\">Blocker in EGO<\/a><\/div>\n<\/div>\n<p>Then use the ON\/OFF switch to install\/uninstall the extension. You need to install browser extension first if it prompts and refresh.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48266\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser-700x441.webp\" alt=\"\" width=\"610\" height=\"384\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser-700x441.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser-300x189.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser-768x484.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/03\/blocker-browser.webp 1156w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Uninstall hBlock<\/h3>\n<p>To uninstall hBlock, you may first disable blocking ads by running command in terminal (Ctrl+Alt+T):<\/p>\n<pre>hblock -S none -D none<\/pre>\n<p>Then, delete the script:<\/p>\n<pre>sudo rm \/usr\/local\/bin\/hblock<\/pre>\n<p>If need, restore <code>\/etc\/hosts<\/code> from the backup file:<\/p>\n<pre>sudo mv \/etc\/hosts.backup \/etc\/hosts<\/pre>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to block ads, trackers, and malware domains system-wide in Ubuntu and other Linux desktop using hBlock. hBlock is a free open-source script that collects a large list of domains that serve ads, tracking scripts and malware from multiple sources. It blocks them by mapping all those domain names to 0.0.0.0 using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":48259,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2039],"class_list":["post-48258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-security"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/48258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=48258"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/48258\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/48259"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=48258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=48258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=48258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}