MikroTik Firewall: Block ads on websites

Block ads on the Internet using the capabilities of MikroTik devices. Blocking is carried out using an address list (with a list of ad networks) and Firewall rules.

We block the display of advertisements from major ad networks, but you can also add your own ad networks (which are used on the sites you visit).

Remember that displaying advertisements is a means of rewarding site authors (eg MHelp.pro).

Blocking ad networks can also cause problems with logging into ad accounts on websites. Consider this if you or your users are webmasters.

Content

  1. Create Address list
  2. Create Firewall Rule
  3. Add ad network address to block list
  4. How to find ad networks on site
  5. List of popular ad networks

Article in other languages:
?? – MikroTik Firewall: Bloquear anuncios los sitios web
?? – MikroTik Firewall: Блокировка рекламы на сайтах
?? – MikroTik Firewall: Bloquer les publicités sur les sites Web
?? – MikroTik Firewall: Blockieren Sie Anzeigen auf Websites
?? – MikroTik Firewall: Advertenties op websites blokkeren

Create Address list

Let’s create an AdNetworks address list and add ad network domains to it.

[IP] -> [Firewall] -> [Address Lists] ->[+] -> [Name: AdNetworks ] -> [Comment: Blocking IP addresses of ad networks from this list.]

Using terminal:

/ip firewall address-list add list="AdNetworks" comment="Blocking IP addresses of ad networks from this list."
MikroTik Blocking ads on sites. Create a list of ad networks to block

Create Firewall Rule

We create a firewall rule that, upon detecting traffic from ad networks (AdNetworks list), puts the IP address of the ad network in the block list – BlackList (from the article “MikroTik Protection (basic device security setting)“).

[IP] -> [Firewall] -> [Raw] -> [+] -> [General: Chain=prerouting; Advanced: Src. Address List=AdNetworks; Action: add src to address list=BlackList, Timeout=2d 00:00:00; Comment="Rule #25 \"AdNetworksList\": drop connections from ad networks."]

Use terminal:

/ip firewall raw add chain=prerouting src-address-list=AdNetworks  action=add-src-to-address-list address-list=BlackList address-list-timeout=2d comment="Rule #25 \"AdNetworksList\": drop connections from ad networks."

Place the rule in the Raw table according to its number in the comment.

Firewall MikroTik rule to block IP addresses from the list of ad networks

Add ad network address to block list

Google is the most popular advertiser, block the following ad network domains:

  • adservice.google.com;
  • tpc.googlesyndication.com.

Add the domain to the AdNetworks address list:

[IP] -> [Firewall] -> [Address Lists] ->[+] -> [Name: AdNetworks; Address: adservice.google.com] -> [Comment: * Google ads]
Adding ad network domain names to the block list

Add other domain names in the same way or execute in the terminal:

/ip firewall address-list add address=tpc.googlesyndication.com list=AdNetworks comment="* Google ads"

You can also block the Google Tag Manager service, which is used to add third-party scripts to a web page:

/ip firewall address-list add address=securepubads.g.doubleclick.net list=AdNetworks comment="* Google Tag Manager"

If you use Russian-language sites, add the local advertising networks Yandex and Relap to the block list:

/ip firewall address-list add address=an.yandex.ru list=AdNetworks comment="* Yandex ads"
/ip firewall address-list add address=relap.io list=AdNetworks comment="* Relap.io ads"

For other countries, you can add to the block list, the Criteo ad network:

/ip firewall address-list add address=static.criteo.net list=AdNetworks comment="* Criteo ads"

I use the * character in every comment to filter values and easily view the list of blocked networks.

Show list of blocked ad networks

How to find ad networks on site

Instructions for Google Chrome:

  1. Open the page of the site with advertising;
  2. Open Developer Tools (F12 key or Ctrl+Shift+I combination);
  3. Turn on the display of Coverage in the panel;
How to find ad networks on the site. Google Chrome enabling Developer Tools
  1. Click the button Start instrumenting coverage and reload page;
Google Chrome enabling Coverage in Developer Tools
  1. Filter by Javascript and sort by URL.
Google Chrome displaying ad network scripts on the site

Now you can see all scripts used on this web page and add scripts from unwanted domain names to the AdNetworks list.

I do not recommend adding a large number of ad networks to the block list – this can significantly increase the CPU load on weak routers. But blocking major ad networks can significantly reduce the number of ad units displayed for all devices on your network (especially mobile).

Large ad networks (Google, Yandex) use ad moderation and set rules that limit the position or number of ad units on a page. Blocking the more “junk” ad networks is probably the best solution.

Advertisements are a way of income for webmasters, motivating them to create quality content.

List of common ad networks (will be updated)

Worldwide ad networks

Google, Criteo, Adsafeprotected.

/ip firewall address-list add address=tpc.googlesyndication.com list=AdNetworks comment="* Google ads"
/ip firewall address-list add address=adservice.google.com list=AdNetworks comment="* Google ads"
/ip firewall address-list add address=static.criteo.net list=AdNetworks comment="* Criteo ads"
/ip firewall address-list add address=static.adsafeprotected.com list=AdNetworks comment="* Adsafeprotected ads"
/ip firewall address-list add address=cdn.adsafeprotected.com list=AdNetworks comment="* Adsafeprotected ads"

Russian-language ad networks

Yandex, Relap.

/ip firewall address-list add address=an.yandex.ru list=AdNetworks comment="* Yandex ads"
/ip firewall address-list add address=relap.io list=AdNetworks comment="* Relap.io ads"

If you find popular ad networks (global or regional), write in the comments, I will add the rules to the article.


In addition to advertisements, analytics systems are installed on sites that violate your privacy and collect data, about blocking analytics systems and increasing privacy on the Internet, will be in the next article.

? How to block ads on websites using MikroTik equipment was discussed in this article. I hope you can now reduce the number of displayed ads for devices on your network. However, if you run into any problems while setting up, feel free to write in the comments. I will try to help.

2 thoughts on “MikroTik Firewall: Block ads on websites”

Leave a Comment