Self-Host AdGuard Home with Docker to Block Ads Network-Wide
Ads and trackers follow you across every device: phones, laptops, smart TVs. Browser extensions only cover one browser at a time, and public DNS blockers hand your query history to a third party. A DNS-level blocker stops unwanted domains before they load, on any device that uses it. In this tutorial we build a private AdGuard Home server on your own VPS, running in Docker. DNS is open only to…
Ads and trackers follow you across all your devices, including phones, laptops, and smart TVs. Browser extensions can only block ads in one browser at a time, while public DNS blockers reveal your query history to a third party. A DNS-level blocker stops unwanted domains before they even load on any device that uses it. This tutorial will guide you through setting up a self-hosted AdGuard Home server on your own virtual private server (VPS) using Docker.
The DNS server will only be accessible to your own IP address, and the dashboard will be protected and reachable only through an SSH tunnel. Self-hosting means you have control over the logs, blocklists, and who can use the server, without any subscription fees.
To get started, you'll need a VPS with Ubuntu 24.04, at least 2 vCPU and 4 GB RAM. Any VPS provider will do, and the tutorial provides an affiliate link to VDSina that supports this channel without extra cost. Ensure you have an SSH connection to the VPS.
First, update the system and install pending upgrades, including security fixes. This can be done without interactive prompts. Then, install Docker using the official convenience script. Installing Docker in a container isolates AdGuard Home, making it easy to update.
Next, disable port 53, which is already occupied by Ubuntu's built-in resolver. Point the resolv.conf file to the real upstream configuration and restart the service. This allows the server to resolve names normally while not using port 53.
Create a compose file in the /opt/adguard directory. This file sets up AdGuard Home to use host networking, enabling direct DNS traffic to the container. It also mounts two folders for configuration and data, which remain intact during updates. The service is set to restart automatically after a reboot.
Restrict access to the DNS server with UFW (Uncomplicated Firewall). Deny all incoming traffic by default, keep SSH open, and allow port 53 only from your current IP address. Update the rule if your home IP changes.
Start AdGuard Home with a single docker compose command, which pulls the image and starts the service in the background. Once the image is downloaded, startup takes only a few seconds.
Complete the setup wizard from the terminal instead of using the browser interface. Generate a random password, store it in a root-only file, and send the configuration to AdGuard's local API. The dashboard remains closed to the internet and can be accessed from your PC through an SSH tunnel on port 3000.
Finally, add a blocklist using the OISD Small list, which blocks ads and trackers while rarely breaking sites. Query the server using dig to verify DNS blocking. Test both normal domains and ad domains to ensure the blocker is functioning correctly. Common mistakes include leaving port 53 open to the entire internet, which makes your server vulnerable to attacks, and skipping the stub listener fix, which causes AdGuard to fail to start. Regularly update your blocklist and monitor the dashboard's query log.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to