GL-inet router adblock via hosts file

Why use ad-blocking?

  • User Experience: Ads can disrupt browsing, taking up screen space, auto-playing videos, or redirecting users.
  • Performance: Ads and tracking scripts slow down page load times.
  • Data Usage: Ads consume extra data, which can be costly or slow down browsing.
  • Privacy: Ads with trackers invade user privacy.
  • Security: Blocking ads reduces the risk of encountering malware.

Using the /etc/hosts file for ad-blocking:

  • Redirect requests for ad servers to a non-routable IP address.
  • Blocked content from a domain will not load.

Advantages:

  • System-wide blocking, not limited to a specific browser or app.
  • Lightweight, no additional software installation required.

Disadvantages:

  • Limited granularity, cannot block specific elements on a page.
  • Maintenance required to update the /etc/hosts file.
  • Some websites detect ad-blockers and restrict content.

For users who prefer not to manually update the /etc/hosts file, there are projects and communities that maintain curated lists of ad-serving domains.

In summary, while the /etc/hosts method is a simple and effective way to block ads system-wide, dedicated ad-blocking software or browser extensions offer more control and flexibility.

Download from OISD source

  1. https://big.oisd.nl/domainswild2
  2. https://small.oisd.nl/domainswild2
# One line script execute in your router ~ 

{
  cat <<-EOF
nameserver 127.0.0.1
nameserver ::1
nameserver 94.140.14.14
nameserver 9.9.9.9
EOF
} > /etc/resolv.conf

{
  cat <<-EOF
127.0.0.1 localhost
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
  curl https://big.oisd.nl/domainswild2 | grep -v '^#' | grep -v '^[[:space:]]*$' | sed 's/^/0.0.0.0 /'
} > /etc/hosts.tmp && mv /etc/hosts.tmp /etc/hosts && echo "Hosts file updated." && \
/etc/init.d/dnsmasq restart && echo "dnsmasq restarted successfully. && Hosts is updated" || \
(echo "An error occurred. Please check the commands and try again." && exit 1)

Replace the first line with regex ^ to this format and save file.

127.0.0.1 localhost
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

0.0.0.0 0--foodwarez.da.ru
0.0.0.0 0-24bpautomentes.hu
0.0.0.0 0-29.com

Upload and replace router default hosts file via SCP

## Install SCP first 
opkg update
opkg install openssh-sftp-server nano bind-dig

# Upload file
scp -P 22 oisd_big_domainswild2.txt [email protected]:/etc/hosts

Restart dnsmasq service

/etc/init.d/dnsmasq restart

/etc/init.d/dnsmasq status

Check local resolv is okay

## Test will return 0.0.0.0
dig 0-29.com +short

# Dig command not found then install
opkg install bind-dig

Check default resolver

root@GL-AX1800:~# cat /tmp/resolv.conf
search lan
nameserver 127.0.0.1
nameserver ::1