I have been using the Docker + Compose + Portainer combo for some smaller services in my homelab. Recently, Podman has gained traction as a more secure way to run containers [1]. I actually never tried to run rootless container using Docker, but it seems it is much more simpler to do so using Podman.

Recently I got an old laptop that I use as a secondary node for my homelab. So I decided to try tinkering with Podman to run a second AdGuard Home DNS server in a rootless container.

If you have not installed Podman yet, I recommend this blog post as it shows the end-to-end process from installing Podamn to deploying apps with it with a practical example [2].

Environment

  • Debian 13
  • Podman v5.4.2

Quadlet Config

This is my Quadlet service file for the AdGuard container:

# ~/.config/containers/systemd/adguardhome.container

[Unit]
Description=AdGuard Home DNS server
Documentation=https://adguard-dns.io/kb/adguard-home/overview/
Wants=network-online.target
After=network-online.target

[Container]
ContainerName=%N
Image=docker.io/adguard/adguardhome:latest
AutoUpdate=registry

HostName=%N

PublishPort=0.0.0.0:5353:53/udp
PublishPort=0.0.0.0:5353:53/tcp
PublishPort=0.0.0.0:5380:80/tcp
PublishPort=0.0.0.0:5300:3000/tcp

Volume=%h/containers/storage/%N/conf:/opt/adguardhome/conf
Volume=%h/containers/storage/%N/work:/opt/adguardhome/work

[Service]
Restart=always
TimeoutStartSec=300

[Install]
WantedBy=default.target

The key details here is this part:

PublishPort=0.0.0.0:5353:53/udp
PublishPort=0.0.0.0:5353:53/tcp

Here we mapped port 53 of the container to port 5353 of the host. Non-root processes can only bind ports 1024 and above, whereas the native DNS port is 53.

We can use the sysctl config:

net.ipv4.ip_unprivileged_port_start=53

But this approach opens all ports from 53 to 1024 to be used by non-root users. This does not sit right with me, and I prefer to only modify the port 53 behaviour.

Port Redirection with nftables

I previously often used iptables for port redirection and ip forwarding configurations, but apparently in modern Debian it is using iptables-nft as the translation layer over nftables [3]. So I might as well learn something new and use nftables directly here.

First make sure that port 53 is not used by any process:

sudo ss -lnup 'sport = :5353' 

nftables should be included with Debian but can be installed with apt as usual:

sudo apt install nftables

The nftables configuration lives in /etc/nftables.conf. You can put the rules directly in this file but I prefer individual config files for each use case in /etc/nftables.d/:

mkdir /etc/nftables.d

Then create a new config file inside that folder:

# /etc/nftables.d/01-dnsredirect.conf

table ip nat {
    chain PREROUTING {
        type nat hook prerouting priority dstnat; policy accept;
        tcp dport 53 redirect to :5353
        udp dport 53 redirect to :5353
    }
}

You can name the config file however you want. This rule block essentialy redirects all packets arriving to the host on port 53 to port 5353 (which is the published port of our AdGuard container).

On my installation, I must put the include directive manually to include config files inside the /etc/nftables.d/ directory at the end of the main config file:

# /etc/nftables.conf

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
	chain input {
		type filter hook input priority filter;
	}
	chain forward {
		type filter hook forward priority filter;
	}
	chain output {
		type filter hook output priority filter;
	}
}

include "/etc/nftables.d/*.conf"

Enable and execute the nftables service:

sudo systemctl enable --now nftables

Verify if the rules are loaded:

sudo nft list ruleset

Start the Container

Finally, start the container as a non-root user:

systemctl --user start adguardhome.service

And that’s it, now any DNS query to the host will be redirected to the AdGuard container.

Additional Notes

On my host machine, I configured it to use external DNS service like 1.1.1.1 for itself. If you want the host to also use the AdGuard container as the default DNS service, you must add additional rules to the nftables config:

# /etc/nftables.d/01-dnsredirect.conf

table ip nat {
  chain prerouting {
    ... (same as before)
  }
  chain output {
    type nat hook output priority dstnat; policy accept;
    tcp dport 53 redirect to :5353
    udp dport 53 redirect to :5353
  }
}

This ensures all packets that leave the system on port 53 also redirected to port 5353.

References