Notes4 min read
How I went ad-free on all devices: TV, phones and laptops at home
Blocking ads on every device at home, so the only thing selling me stuff is my own impulse control.
Hello devs,
Today I’m gonna tell how i blocked ads from everywhere on devices connected to my home router.
This summer vacation while surfing my smart TV i came across a lot of ads, even premium subscriptions of Hotstar and Prime Video also shows ads, and i dont think people would really pay for youtube premium these days.
So to get rid of this ads-everywhere problem i searched the internet and found about PiHole. An opensource software which allows you to block ads on all websites network-wide. What it does is that it filters every request through itself and just blocks the DNS of ads.
How that normally works is: the device asks the DNS server directly and gets the address back. But when we bring PiHole in the picture what it does is, it redirects the device request to itself and filters the dns requests.
Now setting up Pi-Hole
Although the most convenient and best practice to use pihole is by using a raspberry pi as it stays on all the time and will keep the piHole running all the time so blocking thing happens all the time but since I’m broke (else i’d have paid for youtube premium) I did the whole setup on Docker for which the docker-compose.yml file looked something like this
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
# DNS Ports
- "53:53/tcp"
- "53:53/udp"
- "8080:80/tcp"
environment:
TZ: 'Asia/Kolkata'
FTLCONF_webserver_api_password: 'YOUR_PASSWORD'
FTLCONF_dns_listeningMode: 'all'
volumes:
- ./etc-pihole:/etc/pihole
- ./etc-dnsmasq.d:/etc/dnsmasq.d
cap_add:
- NET_ADMIN
- SYS_TIME
- SYS_NICE
restart: unless-stoppedhere i made a container named pihole and downloaded its image and then assigned ports to it
The part where I struggled the most is that port 53 is being used by the OS to change DNS to IP by running a program called systemd-resolved. I’ll tell you the fix to all of that one by one.
1. Permission denied on the Docker socket
First issue that would come when you run the docker container by
docker compose up -dit will say: permission denied while trying to connect to the Docker daemon socket. To fix that run
sudo usermod -aG docker $USER
newgrp dockerthis first command modifies the user and adds user (i.e. you) to the docker group. here usermod stands for user modification, -a means append, G is for group and $USER tells that user is to be appended. Have a question why? Because docker protects /var/run/docker.sock which is the socket used to talk to Docker daemon. So after adding USER -> you to the socket, docker trusts you and now allows you to run it.
Now for newgrp docker: normally group changes take effect only after logout or login but when you run this command it instantly refreshes your permissions.
2. Port 53 already in use
Now the issue which took all my time: bind: address already in use 0.0.0.0:53, which means port 53 is already in use. To find what is using the port i ran
sudo lsof -i :53which tells what is using the port 53 which i found as systemd-resolved. So in ubuntu the port 53 is used to convert the dns to ip addresses.
To verify if pi-hole even runs or not i ran it on a different port and changed the port in the yml files to
ports:
- "8053:53/tcp"
- "8053:53/udp"
- "8080:80/tcp"which maps host 8053 to container internal 53. This works locally such that i can block ads but only on my pc, but i didnt want that, i wanted ad free world for everyone at home.
I then changed the ports to what it was before, “53:53”. And at first what i did was i stopped the systemd-resolved using
sudo systemctl stop systemd-resolvedafter which the container started, but my internet stopped. i couldnt access any website on my laptop, it showed network error everytime i tried to connect to a website. The problem wasn’t the network connection itself. DNS resolution had disappeared because Ubuntu depends on systemd-resolved.
The proper solution
Instead of stopping the service completely, I edited:
sudo nano /etc/systemd/resolved.confand changed
#DNSStubListener=yesto
DNSStubListener=nothen restarted it
sudo systemctl restart systemd-resolvedThis keeps Ubuntu’s DNS functionality while freeing port 53 for Pi-hole.
Therefore after freeing port 53, i started the docker container again
docker compose down
docker compose up -dand this time the container started successfully and the dashboard was available on http://localhost:8080/admin
Now connecting my phone
First connect your home wifi, then open wifi settings and set IP settings to Static. Keep the ip address as it is, for example Phone IP: 192.168.1.32. PiHole works on the LAN ip address of the machine running it, which you can find by running the command
hostname -Ifor me it was: 192.168.1.34. So for DNS 1 put 192.168.1.34, and make sure to do the same for DNS 2, because if DNS 2 is Google’s DNS, ad requests that Pi-hole would block might fall through to Google’s DNS as a fallback, bypassing Pi-hole entirely. So if it isnt changed ads still show up. Therefore put DNS 2 as 192.168.1.34 too.
BOOM IT WORKS. You can open youtube and watch endlessly, it wont show any ads. You can change the dns for your smart TV too.
BTW THIS THING ONLY WORKS TILL YOUR LAPTOP IS ON