
There are various ways to block internet advertisements (ads). One of the most popular ones is using a browser extension. But what happens when you want to use ads that run on other apps or even mobile games? In such a case, you need to block ads from their source, that is, directly on the network. This is where AdGuard comes in. With AdGuard, you can block all or most ads by making AdGuard act as an intermediary (a DNS server) that filters content between your network and the internet.
In this article, you will install and set up AdGuard Home on Ubuntu 24.04, enable TLS encryption with automatic renewals, and configure custom DNS settings. You can choose between two installation methods: Docker and the official installation script.
Before you begin,
adguard.example.com, replace it with your own domain.AdGuard Home is a tool that blocks ads and malicious domains across your entire network. It works by acting as your DNS server. When a device on your network tries to access the internet, AdGuard checks whether the requested domain is on a blocklist. If it is, AdGuard stops the connection and prevents the ad or tracker from loading by returning a fake IP address.
Unlike browser extensions that only block ads on one device, AdGuard filters all DNS traffic from every device connected to your network. It also keeps your internet activity private from your internet provider with features like encrypted DNS.
Ubuntu 24.04 uses systemd-resolved for local DNS caching and resolution, which binds to port 53 by default. AdGuard Home requires this port for DNS services. Follow the steps below to reconfigure systemd-resolved and free port 53.
Create the /etc/systemd/resolved.conf.d directory to store a new config file.
Create and edit the new config file /etc/systemd/resolved.conf.d/adguardhome.conf.
Creating a new config file instead of editing the existing one ensures that the changes are not overwritten during system upgrades.
Add the following contents to the file.
Save and close the file. The above configuration:
127.0.0.1, which is Adguard home.DNSStubListener, which frees up port 53./etc/resolv.conf is the file most programs read to know which DNS server to use. This file is a symlink to /run/systemd/resolve/stub-resolv.conf, which points to 127.0.0.53. After disabling the DNSStubListener, this config breaks. You need to update the symlink:
Back up the existing resolv.conf file.
Create a new symlink pointing to /run/systemd/resolve/resolv.conf.
This step ensures that applications now use the DNS server defined in adguardhome.conf. The file /run/systemd/resolve/resolv.conf dynamically reflects the active resolver settings from systemd-resolved, including the override you added in /etc/systemd/resolved.conf.d/adguardhome.conf. Now, all DNS queries get redirected to 127.0.0.1, where AdGuard Home is listening.
Restart systemd-resolved to apply the changes.
Verify port 53 is free.
The command should return no output.
Configure UFW to allow connections to the required AdGuard Home ports before installing and configuring.
Allow DNS traffic on port 53.
Allow DNS-over-TLS and DNS-over-QUIC port 853.
DNS-over-TLS uses TCP protocol, whereas DNS-over-QUIC uses UDP protocol.
The initial AdGuard Home setup interface runs on port 3000. Allow it.
Allow HTTP traffic for the web dashboard and certificate verification.
Allow HTTPS for the secure web interface and enable DNS-over-HTTPS.
Reload UFW to apply the firewall rules.
You can install AdGuard Home using Docker or the official install script. Both methods provide the same functionality.
Install Docker on your server.
Add your user to Docker group.
Update the Docker group membership.
Create the project directory structure.
Navigate to the project root path.
Create a Docker Compose configuration file.
Add the following configuration.
Save and close the file. This file defines:
adguard/adguardhome:latest image.network_mode: host so the container shares the host’s network stack and can bind directly to DNS port 53.(NET_ADMIN, NET_BIND_SERVICE, NET_RAW) to allow the container to handle low-level networking and bind to privileged ports.Start the AdGuard Home container.
This command:
Verify the container is running.
This section covers generating Let's Encrypt certificates for secure HTTPS access to the AdGuard Home dashboard.
Install Certbot for certificate generation.
Generate a certificate for your domain. Replace adguard.example.com with your actual domain and admin@example.com with your email address.
Output:
Create a certificate copy script based on your installation method.
For Docker installation:
For Script installation:
Add the certificate copy script content. Replace adguard.example.com with your actual domain.
For Docker installation:
Save and close the file. Then, update the script with your actual username. Replace all instances of YOUR_USERNAME with your system username.
For Script installation, add the following content:
Make the script executable and run it.
For Docker installation:
For Script installation:
Check the certificates.
For Docker:
For Script installation:
You should see cert.pem and key.pem files with the correct permissions.
Let's Encrypt certificates expire every 90 days. In this section, configure automatic renewal of your TLS certificates.
Create a Certbot renewal hook script.
Add the renewal script content based on your installation method.
For Docker installation:
Replace YOUR_USERNAME with your username.
For Script installation:
Save and close the file.
Make the renewal hook executable.
To handle port 80 conflicts during renewal (since AdGuard Home binds to port 80 after setup), create stop and start scripts, then add pre-hooks and post-hooks to the Certbot renewal configuration. This temporarily stops AdGuard Home before the renewal attempt and starts it afterward.
For Docker installation:
Create a stop script.
Add:
Create a start script.
Add:
Make them executable.
Update the scripts with your actual username.
For Script installation:
Create a stop script.
Add:
Create a start script.
Add:
Make them executable.
Edit the Certbot renewal configuration to add the hooks. Replace adguard.example.com with your domain.
Add or update under the [renewalparams] section:
For Docker installation:
Replace YOUR_USERNAME with your username.
For Script installation:
Save and close the file.
Test the automatic renewal process.
Output:
Access the AdGuard Home web interface to complete the initial configuration.
Open your web browser and navigate to the setup interface.
Click Get Started on the welcome page.
Set Up the Admin Web Interface:
80Configure the DNS Server:
53Click Next and create an administrator account with a username and a strong password.
Click Next. You'll land on the Configure your devices page, where you'll see the configuration settings for various types of devices. Click Next.
Click Open Dashboard to access the main interface.
Remove port 3000 from the firewall after completing initial configuration.
Configure HTTPS access using your TLS certificates for secure dashboard access.
Access the AdGuard Home dashboard and log in to the dashboard with the credentials you set earlier.
Click the Settings button on the top navigation menu, and click Encryption settings.
Configure the following encryption settings:
Enable Encryption: Check to enable.
Server name: Enter your domain name.
Redirect to HTTPS automatically: Enable.
HTTPS port: 443
DNS-over-HTTPS port: 443
DNS-over-TLS port: 853
DNS-over-QUIC port: 853
Configure certificate paths:
Select Set a certificates file path option.
For Docker installation:
/opt/adguardhome/certs/cert.pem/opt/adguardhome/certs/key.pemFor Script installation:
/opt/AdGuardHome/certs/cert.pem/opt/AdGuardHome/certs/key.pemClick Save to apply the encryption settings. After enabling encryption, access AdGuard Home using https://adguard.example.com.
AdGuard Home supports encrypted DNS protocols to prevent ISPs and third parties from monitoring your DNS queries. Configure upstream DNS servers that support DNS-over-HTTPS (DoH) or DNS-over-TLS (DoT) for enhanced privacy.
Click the Settings button on the top navigation menu, and click DNS Settings.
In the Upstream DNS servers field, add encrypted DNS providers of your choice, such as:
These upstream servers use HTTPS or TLS encryption to secure DNS queries between AdGuard Home and the upstream providers. The encrypted protocols prevent your ISP from seeing which domains you're resolving.
Configure Fallback DNS servers for redundancy. These servers are used when encrypted upstream servers are unavailable. Add DNS servers of your choice, such as:
Fallback servers typically use standard unencrypted DNS (port 53) because they serve as emergency backups when encrypted connections fail. During normal operation, AdGuard Home uses only the encrypted upstream servers.
Configure Bootstrap DNS servers. These servers resolve the domain names of your encrypted upstream servers (like dns.cloudflare.com). You can add:
Enable the following DNS features:
Click Save to apply the DNS configuration.
AdGuard has a built-in DNS filter, but you can expand its capabilities by adding additional blocklists. These publicly maintained lists contain tens of thousands of known ad, tracker, malware, and telemetry domains.
From the top navigation menu, click Filters and select DNS blocklists.
Click Add blocklist and click Choose from the list.
Select the options in the image below, then click Save.
Browse the internet for a while, then check your AdGuard Home dashboard on your browser.
You would see all the sites, trackers, and ads that have been blocked.
DNS rewrites are rules that override standard DNS resolution by mapping specific domain names to custom IP addresses. AdGuard supports DNS rewrites, which allow you to map domain names to specific IP addresses within your network. This acts like a mini local DNS server for internal use. For example, you can map adguard.home to SERVER-IP, to access your AdGuard dashboard. Follow the steps below to access your AdGuard Home dashboard with adguard.home instead of your server IP address.
You can configure your devices to use AdGuard Home as their DNS server. The configuration varies between different types of devices. The section below covers setting up your router to use your AdGuard Home server as a DNS server.
Configure your router to apply AdGuard Home DNS to all connected devices automatically.
http://192.168.1.1 or http://192.168.0.1).You can find configuration settings for most device types from the Setup Guide option on the top navigation menu of AdGuard Home dashboard.
AdGuard Home shows statistics about DNS queries on its dashboard.
Access the dashboard at https://adguard.example.com. You should see logs of DNS queries that reached your AdGuard Home DNS server.
You have successfully deployed AdGuard Home on Ubuntu 24.04 with automatic TLS certificate renewal and encrypted DNS protocols using the official installation script and Docker. To learn more about using it, refer to the AdGuard Home Wiki page.
0 Comments
Be the first to comment and share your perspective with the community.