
Installing an adblock on your OpenWRT router is a straightforward process.
You can install the uBlock Origin package from the OpenWRT package manager, which is available in the "Packages" section of the LuCI web interface.
First, you need to enable the "Unstable" repository in the package manager, which is required for installing the latest version of uBlock Origin.
To do this, navigate to the "Settings" page in the LuCI web interface and select the "Update lists" option.
The latest version of uBlock Origin can be installed by searching for the package in the OpenWRT package manager and selecting it for installation.
Once the installation is complete, you can configure the uBlock Origin settings by navigating to the "Services" page in the LuCI web interface and selecting the "uBlock Origin" option.
Recommended read: Openwrt Interface
Installation and Setup
To install adblock on your OpenWrt router, first connect to it via SSH. You can then use the automated interactive setup in adblock-lean, which makes it easy to get going. If you prefer manual setup, you can use the following commands.
Recommended read: Openwrt Build System Setup
You can also install adblock using the web interface System->Software or ssh to the router and use the CLI package manager opkg. The last item libustream-openssl is required to download the block lists over TLS (or https).
To install adblock-lean manually, you'll need to check which config dnsmasq sections are defined in /etc/config/dhcp. If you have multiple config dnsmasq sections, you should know which dnsmasq instance you want adblocking to work on.
If you have only one config dnsmasq section, you can ignore the following section. However, if you have multiple config dnsmasq sections, you'll need to note the instance index, instance name, and confdir (if set). You can use the command /etc/init.d/dnsmasq info to get a list of all running instances as json.
To adblock on multiple dnsmasq instances, you'll need to specify multiple indexes and their corresponding conf-dirs in the adblock-lean config file. You can also enable blocklist compression to reduce RAM usage by adding the lines "option blocklist-compress yes" and "option blocklist-compress-format gz" to the relevant dnsmasq section.
You can also install adblock using a script by running the following command: wget --no-check-certificate -qO - https://raw.githubusercontent.com/stangri/openwrt-simple-adblock/master/adblock | /bin/sh -s setup. This script manipulates the /etc/banner file to reflect the status of the adblock if the /etc/banner.orig file exists.
Broaden your view: Upgrade Openwrt from Command Line
Here's a summary of the steps to install adblock:
- Connect to your OpenWrt router via SSH
- Use the automated interactive setup in adblock-lean or manual setup
- Check which config dnsmasq sections are defined in /etc/config/dhcp
- Note the instance index, instance name, and confdir (if set)
- Specify multiple indexes and their corresponding conf-dirs in the adblock-lean config file
- Enable blocklist compression to reduce RAM usage
Features and Configuration
Adblock-fast is super-fast due to its parallel downloading and processing of block-lists and fast block-list parsing code.
You can configure everything from the Web UI, including adding your own domains to the allow-list or block-list.
Adblock-fast supports multiple remote allow/block-lists formats, as well as using a remote dnsmasq config file with no parsing.
The adblock-fast configuration parameters are split into basic and advanced tabs in the Web UI settings.
Some of the key configuration parameters include support for multiple blocklist and/or allowlist files downloaded from user-specified URLs, as well as local blocklist and/or allowlist files specified by the user.
Adblock-fast has a strong emphasis on performance, user-friendliness, reliability, error checking and reporting, code quality and readability.
Here are some of the key features and configuration options:
- Supports multiple blocklist and/or allowlist files downloaded from user-specified URLs
- Supports local blocklist and/or allowlist files specified by the user
- Configurable constraints for minimum and maximum size and lines count in blocklist/allowlist parts and in the final blocklist
- Supports concurrent download and processing of blocklist/allowlist parts for faster blocklist updates
- Supports pause and resume of adblocking without re-downloading blocklist/allowlist parts
Features
Features are what make a product stand out, and when it comes to ad-blocking, you want a solution that's fast, reliable, and easy to use. Adblock-lean supports multiple blocklist and/or allowlist files downloaded from user-specified URLs.
This feature is particularly useful for users who want to customize their ad-blocking experience. You can easily add or remove domains from your allowlist or blocklist, and even add your own custom lists. Adblock-fast also supports multiple remote allow/block-lists formats.
One of the key benefits of ad-blocking is its ability to reduce memory consumption. Adblock-lean supports blocklist compression, which can significantly reduce memory usage. This is achieved through the use of dnsmasq's new conf-script functionality.
Adblock-fast is also designed to be lightweight and easily hackable. The whole script is contained in a single file, making it easy to modify and customize. This is a great feature for users who want to fine-tune their ad-blocking experience.
Here are some of the key features of ad-blocking solutions:
Adblock-fast also supports concurrent download and processing of blocklist/allowlist parts, making it faster than other solutions. This is especially useful for users with slower internet connections. Additionally, adblock-fast supports pause and resume of adblocking without re-downloading blocklist/allowlist parts.
One of the key advantages of adblock-fast is its ability to block ads served over https. This is a major improvement over other solutions that may not be able to block https ads. Adblock-fast also supports blocking ads inside browsers with built-in DNS-over-HTTPS proxy enabled.
Take a look at this: Setup Openwrt Luci Https through Command Line
Lean Status Check

To check the status of adblock-lean, you can simply run a command in your terminal.
The output will display the current status of your adblock-lean instance.
You can obtain the status of a running adblock-lean instance by running a single command.
adblock-lean automatically checks for version updates at the end of the start and status routines.
If an update is available, adblock-lean will print a message to let you know.
During certain updates, adblock-lean will require a configuration update.
To update adblock-lean to the latest version, you simply need to run another command.
You might like: Hg556 Version C Openwrt
Configuration
Configuration is a crucial aspect of adblock-lean, and it's surprisingly flexible. You can configure it to suit your needs, and it's relatively easy to do so.
The configuration options are internally documented in detail, which is a big plus. This means you can easily find the information you need to make informed decisions.
Advanced configuration is available, and it's quite extensive. You can find the full list of configuration parameters in the /etc/adblock-lean/config file.

The configuration options are divided into several categories, including whitelist mode, blocklist URLs, and allowlist URLs. You can configure these options to suit your needs.
Here's a breakdown of the main configuration options:
- whitelist_mode: enables or disables blocking all domains except those in the allowlists and their subdomains
- blocklist_urls: one or more raw blocklist URLs to download and process
- allowlist_urls: one or more raw allowlist URLs to download and process
- local_allowlist_path: path to local allowlist (included domains will not be blocked)
- local_blocklist_path: path to local blocklist (included domains will be blocked)
These options are just the tip of the iceberg. There are many more configuration options available, each with its own specific purpose.
To make things easier, adblock-lean also provides a way to preserve your configuration across OpenWrt upgrades. Simply backup the necessary files and run the interactive setup again to re-enable adblock-lean.
In the advanced configuration options, you'll also find settings for things like maximum download retries, minimum good line count, and maximum file part size. These options can help you fine-tune your adblock-lean experience.
Overall, the configuration options for adblock-lean are quite comprehensive and flexible. With a bit of experimentation, you can customize it to suit your needs.
Advanced Configuration
Advanced configuration options are internally documented in detail with comments in /etc/adblock-lean/config. You can access these options to fine-tune the adblock settings.
Each configuration option is internally documented in detail with comments in /etc/adblock-lean/config. The options include whitelist_mode, blocklist_urls, and allowlist_urls, among others.
The whitelist_mode option allows you to block all domains except those in the allowlists and their subdomains. It can be enabled or disabled with a 1/0 setting. The blocklist_urls option lets you specify one or more raw blocklist URLs to download and process.
Here are some key configuration options:
These options can be used to customize the adblock settings to suit your needs. For example, you can use the blocklist_urls option to specify additional blocklist URLs to download and process.
Advanced Configuration
Advanced Configuration can be a bit overwhelming, but don't worry, I've got you covered. The configuration options are internally documented in detail with comments in /etc/adblock-lean/config.
You can configure adblock-lean to block all domains except domains in the allowlists and their subdomains by setting the whitelist_mode option to 1. This will enable the whitelist mode.

The blocklist_urls option allows you to specify one or more raw blocklist URLs to download and process. You can also specify multiple URLs by separating them with a comma.
To use an external dnsmasq config file, you can quickly configure adblock-fast by downloading and using the pre-made dnsmasq config file. This will fetch the config file without further processing.
The full list of configuration parameters of adblock-fast.config section is extensive and includes options such as whitelist_mode, blocklist_urls, and allowlist_urls. Each option has a specific description and usage.
You can check the status of adblock-lean by running the status command, which will print the current operation being performed. If adblock-lean is doing something in the background, the status command will let you know what's happening.
The following configuration parameters are available for adblock-fast:
For devices with low memory capacity (less than 512MiB), setting the unload_blocklist_before_update option to auto will cause previous blocklist to be unloaded before downloading and processing a new one.
Internal Version Mismatch

Internal Version Mismatch is a common issue that can occur when visiting the WebUI page of luci-app-adblock-fast. It's essential to ensure that all three internal versions are in sync.
The principal app integrates with the WebUI in a way that requires matching versions of adblock-fast and luci-app-adblock-fast. If you're seeing this message, check the versions reported by opkg or apk on your device.
To resolve the issue, run the following command to ensure the versions match:
If the versions are already matching, but you're still seeing the Version Mismatch message, there might be another issue at play.
In this case, check the compatibility levels of luciCompat and packageCompat. If luciCompat is lower than packageCompat, it means your browser has cached outdated Javascript code for the WebUI. Simply refresh or delete your browser cache to resolve the issue.
However, if rpcdCompat is lower than packageCompat, you'll need to restart the RPCD service. Run the command service rpcd restart and re-login to the WebUI or reboot your device.
Discover more: Openwrt Luci
Blocklists and Updates
You can use a local blocklist or allowlist to supplement and/or override the downloaded blocklists and allowlists. Simply add domains separated by newlines in /etc/adblock-lean/blocklist or /etc/adblock-lean/allowlist.
adblock-lean allows you to allow a subdomain of a blocked domain, a perfectly matched domain from the blocklist, and a higher level domain when subdomains are blocked.
To enable automatic blocklist updates, you can use a cron job. adblock-lean will run according to the schedule specified in the config file, with a random delay of 0-60 minutes.
The automated setup routine offers to set up a daily update schedule and creates a daily cron job with the default blocklist update schedule. To change the update schedule, look for the option cron_schedule= in the config file and define your preferred cron schedule.
Here's an example of a daily update schedule: cron_schedule="0 5 * * *". Make sure that your custom schedule complies to the crontab syntax.
Broaden your view: Openwrt Update Firmware
If you want to disable automatic blocklist updates, change the value for the cron_schedule option to disable. After changing the schedule in the config, run the service adblock-lean upd_cron_job command to have adblock-lean create/update/remove the cron job.
adblock-lean automatically checks for version updates at the end of the start and status routines and prints a message if an update is available. You can update adblock-lean to the latest version by running adblock-lean update.
The lists are maintained on GitHub, and you can find them at https://github.com/StevenBlack/hosts.
Readers also liked: Openwrt Disable Ipv6
Customization and Options
You can customize adblock-fast using the Web UI, found in Services/Simple AdBlock.
To block specific domains, you can add lines to the hosts files, which should include either http:// or https:// (or file:// if curl is installed) prefix.
Some top block-lists are used in the default adblock-fast installation, suitable for routers with at least 8MB RAM.
You can also use the Web UI to add individual domains to be blocked or allowed.
If you want to allow specific domains, you can add them to the domains lists, one per line.
Whitelist Mode
Whitelist mode can be used to implement parental control or similar functionality while also adblocking inside the allowed domains.
This mode can be enabled by setting the config option whitelist_mode to 1. In this mode, all domain names will be blocked, except for domains (and their subdomains) included in local and/or downloaded allowlists.
If blocklists are used in addition to allowlists, addresses which are included in the blocklists and which are subdomains of allowed domains - will be blocked as well.
For example, if an allowlist has this entry: google.com and a blocklist has this entry: ads.google.com, and whitelist_mode is set to 1, then ads.google.com will be blocked, while google.com and mail.google.com (and any other subdomain of google.com which is not included in the blocklist) will work.
Note that in this mode, the test domains (specified via the option test_domains) will be automatically added to the allowlist in order for the checks to pass.
Explore further: Openwrt Google Wifi

You can use empty string in that option - this will bypass that check and block the default domains (google.com, microsoft.com, amazon.com).
The resulting blocklist generated in whitelist mode will be typically much smaller than otherwise, so you may need to reduce the value of the min_good_line_count option in order for the list to be accepted by adblock-lean.
User-defined actions on success, failure, and updates
User-defined actions on success, failure, and updates can be a game-changer for your adblock-lean setup.
You can specify a custom script to be called on success or failure, or when an update is available. This can be used to send an email or SMS, for example.
To get started, you'll need to install a package like mailsend in OpenWRT. I recommend signing up for a free Brevo account, which offers 300 free email sends per day.
You'll need to edit your config file to specify the custom script path. The recommended path is '/usr/libexec/abl_custom-script.sh', which the adblock-lean luci app will have permission to access.

Here's a step-by-step guide to creating the custom script file:
1. Create a file at '/usr/libexec/abl_custom-script.sh'
2. Define the functions report_success, report_failure, and report_update in your script
3. Use user variables in CAPITALS, such as BREVO_PASSWORD, to store sensitive information
Some important notes to keep in mind: the Brevo password is not the same as the one created on sign-up, and you should avoid copy-pasting Windows-style newlines into your script.
How To Customize
You can customize adblock-fast using the Web UI found in Services/Simple AdBlock. It's a user-friendly interface that lets you add, remove, or edit links to various lists.
To block hosts files, simply add the file path with the domain name per line. For example, "127.0.0.1 example.com" would block the example.com domain.
You can also block domains lists, one domain name per line, to be blocked. Make sure to include the http:// or https:// prefix.
Some popular block-lists come pre-installed with adblock-fast, but you can also use AdBlockPlus lists of domains to be blocked.

If you want to allow certain domains, you can create a list of allowed domains, one per line, with the http:// or https:// prefix.
Here are the types of lists you can customize through Web UI:
- Hosts files (127.0.0.1 or 0.0.0.0 followed by space and domain name per line)
- Domains lists (one domain name per line) to be blocked
- AdBlockPlus lists of domains to be blocked
- Domains lists (one domain name per line) to be allowed
Remember to include the correct prefix (http://, https://, or file://) for each list.
Troubleshooting and Issues
If you're experiencing issues with your OpenWrt adblock setup, you're not alone. There are some known issues to be aware of.
One of the main issues is that four very large blocklists are not included by default, which can cause script termination on routers with limited RAM/Flash. This is because their inclusion can be too much for some devices to handle.
If you're experiencing script termination, check the setup function for commented out lines that mention these large blocklists. This will give you an idea of what's causing the issue and how to resolve it.
Worth a look: Adblock Not Working on Youtube June 2024
Known Issues
There are 4 very large blocklists that are not included by default. This is because including them will likely result in script termination on routers with little RAM/Flash.

You'll need to check the setup function for commented out lines to see which ones are not included. This will give you a clear idea of what you're dealing with.
These blocklists are too big to be included by default, so you'll need to carefully consider whether to add them or not.
Check this out: Opera Gx Adblock Not Working
How It Fails
For some devices, the DNS Resolver Options just don't work as expected. This can be due to hardcoded DNS servers on the device, which ignore the router's DNS settings.
Some Android Lollipop 5.0 phones, media-centric tablets, and streaming devices have hardcoded DNS servers that can't be overridden by the router's settings.
To fix this, you can manually set the DNS servers on your device to Google's (8.8.8.8), Cloudflare's (1.1.1.1), or OpenDNS (208.67.222.222).
Another reason for failure is when your device is set to obtain the DNS settings via DHCP, but your router's DNS settings aren't being sent to the device.
If you're using a wireguard "server" on your router and remote clients connect to it, ad-blocking may not work properly for your remote clients until you add a specific configuration to /etc/network.
Check this out: Openwrt Dyndns
Pi Hole and Alternative Solutions
Pi Hole is a popular application that can be run on your Raspberry Pi to block internet ads using DNS (Domain Name Service).
It works by becoming your network's DNS server, controlling which DNS responses have real IP addresses and which are blocked.
Pi Hole claims to support IPv6, but that support is a bit challenging due to the differences between IPv4 and IPv6.
The Pi Hole authors made the classic mistake of thinking IPv6 is just IPv4 with a bigger address.
Readers also liked: Raspberry Pi 5 Openwrt
Requirements and Settings
The required packages for adblock-fast should be automatically installed when you install it. However, to upgrade from dnsmasq to dnsmasq-full, you'll need to connect to your router via ssh and run a specific command.
To block ads, you'll need to install one of the following DNS resolvers on your router: dnsmasq, dnsmasq-full, smartdns, or unbound. The dnsmasq package is usually included in the default OpenWrt installation.
If your router has less than 64Mb RAM, you'll need to edit the configuration file to adjust the ad/malware lists. The configuration file is located at /etc/config/adblock-fast, and it has lists in ascending order starting with the smallest ones.
For your interest: Openwrt Install Tailscale
Requirements
To block ads effectively, you need to install some required packages. The required packages should be automatically installed when you install Adblock-Fast.
You'll also need to upgrade from dnsmasq to dnsmasq-full if you want to use the full version. This can be done by connecting to your router via SSH and running the command to upgrade.
To use the dnsmasq.ipset option, you need to install ipset and dnsmasq-full with ipset support. This is because the dnsmasq-full package in OpenWrt 23.05 and later only supports nftset.
In OpenWrt 22.03 and earlier, dnsmasq-full supports only ipset. If you want to use the dnsmasq.nftset option, you need to install dnsmasq-full with nftset support.
To speed up processing, install the gawk, grep, sed, and coreutils-sort packages. These packages are optional but recommended for faster block-list processing.
Default Settings
The default settings for the service are pretty straightforward. The service is disabled by default, so you'll need to enable it using the Web UI or by running a specific command in the terminal.

To do this, you'll need to use the command `uci set adblock-fast.config.enabled=1; uci commit adblock-fast`. This will enable the service, but you'll also want to consider the amount of RAM your router has.
Routers with 64Mb RAM have a specific set of ad/malware lists that are suitable for their configuration. If your router has less than 64Mb RAM, you'll need to edit the configuration file located at `/etc/config/adblock-fast` to optimize the lists.
Readers also liked: Openwrt Travel Router
Uninstallation and Maintenance
To uninstall adblock-lean, run the command `service adblock-lean uninstall` or `sh /etc/init.d/adblock-lean uninstall`.
If you're looking to remove adblock-lean from your system, you'll need to use one of these commands.
To ensure adblock-lean is properly uninstalled, make sure to run the command from the correct location, typically from the root directory.
Preserve Files and Config Across Upgrades
To preserve your files and config across upgrades, you'll want to back up the adblock-lean files and config.
This is done by adding the files to be backed up in the Configuration tab in LuCi, using your router's IP address.
You'll need to run the interactive setup again after completing the sysupgrade to re-enable adblock-lean.
To preserve your old config, simply answer 'e' when asked if you want to generate a new config or use the existing one.
After running the setup, your adblock-lean config should be preserved.
Check this out: Config Openwrt
Uninstalling

To uninstall adblock-lean, you have two options. You can run the command "service adblock-lean uninstall" in your terminal.
This method is straightforward and gets the job done.
Alternatively, you can also use "sh /etc/init.d/adblock-lean uninstall" to achieve the same result.
Logrotate
Logrotate is a useful tool for managing log files on your USB storage device. You can use it to remove old files automatically and prevent clutter.
The logrotate script directory is located at /etc/logrotate.d. This is where you'll find and manage your scripts.
To add a new logrotate script for adblock, you'll need to set it up on the command line interface (CLI), as there is no LuCi app available.
Frequently Asked Questions
How to block websites on OpenWRT?
To block websites on OpenWRT, navigate to LuCI and set up a new traffic rule under Network > Firewall > Traffic Rules.
Featured Images: pexels.com


