Build Home Router with OpenWrt – Add adblock

1 minute read

Add required packages

  • make menuconfig
  • Network » adblock
  • Network » tcpdump
  • LuCI » 3. Applications » luci-app-adblock

This will add the following options to .config:

+CONFIG_PACKAGE_adblock=y
+CONFIG_PACKAGE_libpcap=y
+CONFIG_PACKAGE_libustream-openssl=y
+CONFIG_PACKAGE_luci-app-adblock=y
+CONFIG_PACKAGE_tcpdump=y

Adblcok Coniguration

Need to enable this service through luci web interface, make sure select these two blocklist sources:

  • malware
  • reg_cn

Click Save & Apply button on the bottom right corner to make it take effects, the whole blacklist will be saved at /tmp/adb_list.overall, this may take sometime depending on the internet.

Block ads on csdn blog

After enabling adblock, and with malware, reg_cn enabled, CSDN blog still show ads from provider youdao.

As adblock was based on DNS, so we can find out the domain name of the ad server, then add them to the blacklist. Run this command and refresh the blog page that have annoying ads and chekck out the dns lookup process:

sudo tshark -f "udp port 53" -Y "dns.qry.type == 1"

example:

   44 1.826701134 192.168.1.235 ? 192.168.1.1  DNS 77 Standard query 0x7536 A gorgon.youdao.com
   46 1.831400837  192.168.1.1 ? 192.168.1.235 DNS 136 Standard query response 0x7536 A gorgon.youdao.com CNAME bf.youdao.com A 220.181.76.83 A 103.72.47.246
   48 2.134388152 192.168.1.235 ? 192.168.1.1  DNS 77 Standard query 0xa525 A gorgon.youdao.com
   50 2.138670699  192.168.1.1 ? 192.168.1.235 DNS 136 Standard query response 0xa525 A gorgon.youdao.com CNAME bf.youdao.com A 103.72.47.246 A 220.181.76.83
   52 2.158053233 192.168.1.235 ? 192.168.1.1  DNS 79 Standard query 0xa142 A shared.ydstatic.com
   54 2.167254515  192.168.1.1 ? 192.168.1.235 DNS 136 Standard query response 0xa142 A shared.ydstatic.com CNAME shared.ydstatic.com.wscdns.com A 150.138.214.121

Add additional blacklist

After finding out the domain name of the ad server, we need to add to adblock. Adblock allows us to add additional entries to the blacklist to meet our need, these entries were save in /etc/adblock/adblock.blacklist.

Take youdao for example, add these two entries to /etc/adblock/adblock.blacklist:

gorgon.youdao.com
ydstatic.com

This can be done via luci interface, navigate to Services » Adblock » Advanced and fill the textbox with the domain above, click save, then go to Overview tab, click Refresh button under Runtime Information section. Runtime Information

If adblock takes effect, nslookup will return NXDOMAIN:

root@OpenWrt:/# nslookup gorgon.youdao.com
Server:		127.0.0.1
Address:	127.0.0.1#53

** server can't find gorgon.youdao.com: NXDOMAIN
** server can't find gorgon.youdao.com: NXDOMAIN