Skip to content

infra VM

The infra VM carries the services the whole house leans on: DNS with ad blocking (AdGuard Home), network health (Prometheus and its exporters, Grafana), central logs (Loki and Alloy) and the UniFi log analyzer (Insights Plus). It is built first among the VMs because every other machine asks it for names.

The stack is one Compose file, vm/infra/compose.yaml, brought up in three stages with profiles: DNS alone, then monitoring, then Insights Plus. The Mac pushes it with scripts/vm-push.sh, which also writes the .env file from 1Password.

Restore and from scratch. Each part says where they differ. In short: restore imports the Pi-hole lists and the Grafana dashboards, and retires the NAS copies at the end. From scratch starts with AdGuard’s default list and the dashboard kept in this repository.

Nothing in this chapter changes the firewall of the network. The VM protects its own ports (step 6.6), and chapter 10 adds the network side.

6.1 Build the base, or adopt the existing VM

Section titled “6.1 Build the base, or adopt the existing VM”

Why. Chapter 5 gives the VM its encrypted disk, console, SSH and Docker. The infra VM built on 2026-11-25 already has most of it.

From scratch. Do chapter 5 with VM=infra.

Restore. Add the bundle carried over in step 2.9 to UTM (double-click it), make sure its name is exactly infra, raise its memory to 4096 MB in its settings, then:

  1. Store its current disk passphrase and user password in 1Password, replacing the generated values, so the unlock script types the right one:
Terminal window
op item edit "LUKS infra" --vault Infrastructure 'password=THE_PASSPHRASE_YOU_CHOSE'
op item edit "VM infra user" --vault Infrastructure 'password=THE_CURRENT_PASSWORD'
  1. Start it, unlock it (vm-unlock infra), and install your new key through the console if the old Mac’s key was the only one: screen "$(vm-tty infra)", log in, then nano ~/.ssh/authorized_keys and paste the output of cat ~/.ssh/mac-admin.pub.
  2. Do steps 5.5 (the two scp lines), 5.6, 5.9, 5.10 and 5.11 with VMIP=10.0.2.5, then install the network file: ssh infra 'sudo install -m 644 /tmp/interfaces /etc/network/interfaces && sudo reboot', and unlock again.
  3. Grow the disk to 96 GB (end of chapter 5).

Verify. ssh infra verify.sh 2 matches the table of step 5.14, and ssh infra free -m | awk '/Mem/{print $2}' prints about 3900.

Rollback. From scratch: delete the VM. Restore: the old Mac still holds the original bundle.

Why. AdGuard’s settings and the GeoIP database live in plain folders under /srv, so a backup is a copy of those folders. iptables-persistent keeps the port rules of step 6.6 across restarts.

infra

Terminal window
sudo install -d -o admin -g admin /srv/stack /srv/adguard/work /srv/adguard/conf /srv/insights/maxmind
echo iptables-persistent iptables-persistent/autosave_v4 boolean false | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean false | sudo debconf-set-selections
sudo apt install -y iptables-persistent

Verify. ls /srv lists adguard insights stack, and systemctl is-enabled netfilter-persistent prints enabled.

Rollback. sudo apt purge iptables-persistent && sudo rm -rf /srv/adguard /srv/insights.

Why. vm-push.sh fills .env from 1Password and stops if one item is missing. Three items do not exist yet.

  1. MaxMind GeoLite2 (Insights Plus places addresses on a map). Sign up free at maxmind.com, then Manage License Keys > Generate new license key.
  2. AbuseIPDB (reputation of outside addresses, 1,000 lookups a day). Free account at abuseipdb.com, then API > Create Key.
  3. NAS SNMPv3. Step 2.13 stored it on the restore path. From scratch, generate it now. Step 11.9 gives the same values to the NAS.

Mac

Terminal window
op item create --vault Infrastructure --category password --title "MaxMind GeoLite2" \
'account id[text]=YOUR_ACCOUNT_ID' 'license key[password]=YOUR_LICENSE_KEY' >/dev/null
op item create --vault Infrastructure --category "API Credential" --title "AbuseIPDB" \
'credential[password]=YOUR_API_KEY' >/dev/null
# from scratch only:
op item create --vault Infrastructure --category password --title "NAS SNMPv3" \
'username[text]=monitor' "auth password[password]=$(openssl rand -hex 12)" \
"priv password[password]=$(openssl rand -hex 12)" >/dev/null

Verify. op inject -i $INFRA/vm/infra/.env.tpl | grep -c 'op://' prints 0, with no error. Every reference resolved.

Rollback. op item delete "<title>" --vault Infrastructure.

Why. latest changes without telling you. The house’s DNS and a program holding a key to your router should change version only when you decide. You resolve each latest once, write the version into the repository, and from then on an update is a visible commit.

infra

Terminal window
for i in adguard/adguardhome prom/prometheus prom/blackbox-exporter prom/node-exporter \
gcr.io/cadvisor/cadvisor prom/snmp-exporter ghcr.io/unpoller/unpoller; do
docker pull -q $i:latest >/dev/null
printf '%-34s %s\n' $i "$(docker inspect -f '{{index .Config.Labels "org.opencontainers.image.version"}}' $i:latest)"
done

Mac Edit $INFRA/vm/infra/.env.tpl and replace each latest with the version printed, written the way the registry tags it (v0.107.57 for AdGuard, v3.0.1 for Prometheus, and so on). If a line printed no version, open the project’s releases page and take the newest stable tag. Then:

Terminal window
cd $INFRA && git add vm/infra/.env.tpl && git commit -m "infra: pin image versions"

Verify. grep -c latest $INFRA/vm/infra/.env.tpl prints 0 (ignoring the comment line: grep -v '^#' vm/infra/.env.tpl | grep -c latest).

Rollback. git revert HEAD.

Why. The Mac is the only machine that talks to git and to 1Password. The VM receives finished files.

Mac

Terminal window
vm-push.sh infra

Verify. It ends with Stack pushed and valid on infra. and ssh infra 'ls /srv/stack; stat -c %a /srv/stack/.env' lists compose.yaml, the config folders, and 600.

Rollback. ssh infra 'rm -rf /srv/stack/*'.

Why. Docker publishes ports past any host firewall, so the limits go in Docker’s own chain. Without them, any device that can route to 10.0.2.5 could push fake log lines or read Prometheus. The script names each port and who may use it.

Port Service Allowed from
53 DNS everyone (the network firewall decides)
8080 AdGuard admin Mac, home VM, admin VPN
9090 Prometheus home VM, Mac, admin VPN
3100 Loki home VM
514/udp Insights Plus syslog the UDM Pro (10.0.2.1)
1514 Alloy syslog the NAS
8443, 8444 Insights Plus, Grafana Mac, admin VPN
9115 blackbox exporter containers on this VM

infra

Terminal window
sudo sh /srv/stack/firewall.sh
sudo netfilter-persistent save

Verify. sudo iptables -S INFRA-FWD | grep -c DROP prints 7, and sudo iptables -S DOCKER-USER | grep -c INFRA-FWD prints 1.

Rollback. sudo iptables -D DOCKER-USER -i enp0s1.2 -j INFRA-FWD; sudo iptables -D INPUT -i enp0s1.2 -j INFRA-IN; sudo netfilter-persistent save.

Why. AdGuard Home replaces Pi-hole and dnscrypt-proxy with one program that blocks ads and talks to its upstream resolvers over encrypted DNS. It uses the VM’s own network, so it sees each client’s real address.

infra

Terminal window
cd /srv/stack && docker compose up -d adguardhome

Mac Open http://10.0.2.5:3000. In the wizard:

Screen Value
Admin web interface All interfaces, port 8080
DNS server All interfaces, port 53
Username admin
Password op read "op://Infrastructure/AdGuard Home admin/password" | pbcopy, then paste

The page moves to http://10.0.2.5:8080. Sign in.

Verify. dig +short @10.0.2.5 debian.org prints addresses, and dig +short @10.0.2.5 doubleclick.net prints 0.0.0.0.

Rollback. ssh infra 'cd /srv/stack && docker compose rm -sf adguardhome && sudo rm -rf /srv/adguard/*/*'.

Why. Encrypted upstreams keep your queries from your provider. Two of them asked in parallel means one slow resolver never slows the house. The default rate limit is meant for servers open to the internet: at home it silently drops lookups from busy clients such as Home Assistant.

Mac AdGuard Settings > DNS settings:

Setting Value
Upstream DNS servers https://security.cloudflare-dns.com/dns-query and https://dns.quad9.net/dns-query, one per line
Mode Parallel requests
Bootstrap DNS servers 1.1.1.2 and 9.9.9.9
Private reverse DNS servers 10.0.2.1, with Use private reverse DNS resolvers and Enable reverse resolving of clients’ IP addresses on
Rate limit 0
Enable DNSSEC on
Optimistic caching on

Click Test upstreams, then Apply. In Settings > General settings: query log retention 24 hours, statistics retention 7 days.

Cloudflare’s security resolver refuses known malware domains, the same choice dnscrypt-proxy made with cloudflare-security.

Verify. Test upstreams reports that all servers work. dig @10.0.2.5 debian.org | grep 'Query time' shows a few milliseconds on the second run.

Rollback. Remove the upstream lines. AdGuard falls back to its default (Quad9).

Why. The lists decide what is blocked. On the restore path you carry Pi-hole’s choices over so the house sees no difference. The loop uses AdGuard’s own API, which is exactly what the web page calls.

Mac

Terminal window
AG="http://10.0.2.5:8080/control"; AGP="admin:$(op read 'op://Infrastructure/AdGuard Home admin/password')"

Restore. Pi-hole’s export holds its database:

Terminal window
cd ~/infra-migration/backups && mkdir -p pihole && unzip -o -q pihole-teleporter.zip -d pihole
DB=pihole/etc/pihole/gravity.db
# blocklists
sqlite3 $DB "select address from adlist where enabled=1" | while read -r url; do
curl -s -u "$AGP" -H 'Content-Type: application/json' "$AG/filtering/add_url" \
-d "$(jq -n --arg u "$url" '{name:$u,url:$u,whitelist:false}')"; echo " $url"
done
# exact allow (type 0) and deny (type 1) entries become custom rules
{ sqlite3 $DB "select '@@||'||domain||'^' from domainlist where enabled=1 and type=0"
sqlite3 $DB "select '||'||domain||'^' from domainlist where enabled=1 and type=1"; } > pihole/rules.txt
curl -s -u "$AGP" -H 'Content-Type: application/json' "$AG/filtering/set_rules" \
-d "$(jq -Rn '{rules:[inputs]}' < pihole/rules.txt)"
# regex entries (types 2 and 3) need a look by hand
sqlite3 $DB "select type, domain from domainlist where enabled=1 and type in (2,3)"

For each regex printed, add a line in Filters > Custom filtering rules: /the-regex/ to block, @@/the-regex/ to allow.

From scratch. Keep the AdGuard DNS filter that is on by default. In Filters > DNS blocklists > Add blocklist > Choose from the list, add OISD Blocklist Big. Two well-kept lists block more reliably than many overlapping ones, and each list sits in memory.

Verify. Filters > DNS blocklists shows the lists with a rule count above zero after Check for updates. dig +short @10.0.2.5 doubleclick.net prints 0.0.0.0.

Rollback. Remove a list with its bin icon. curl -s -u "$AGP" -H 'Content-Type: application/json' "$AG/filtering/set_rules" -d '{"rules":[]}' clears the custom rules.

Why. Two services of this VM are reached by name so their certificates match, and Pi-hole’s local records must keep answering.

Mac

Terminal window
for pair in insights.home.arpa=10.0.2.5 grafana.home.arpa=10.0.2.5 adguard.home.arpa=10.0.2.5 \
ha.home.arpa=10.0.5.2 nas.home.arpa=10.0.2.2; do
curl -s -u "$AGP" -H 'Content-Type: application/json' "$AG/rewrite/add" \
-d "{\"domain\":\"${pair%%=*}\",\"answer\":\"${pair##*=}\"}"
done

Restore. Print Pi-hole’s local records and add any you still use the same way, with the new address of the service:

Terminal window
grep -A30 '^\s*hosts = \[' ~/infra-migration/backups/pihole/etc/pihole/pihole.toml | sed '/\]/q'

Verify. dig +short @10.0.2.5 grafana.home.arpa prints 10.0.2.5.

Rollback. Filters > DNS rewrites, bin icon.

6.11 Cut the house over to the new resolver

Section titled “6.11 Cut the house over to the new resolver”

Why. Until now only you asked 10.0.2.5. This step hands it to every device. The gateway of each network is the second server: the house keeps resolving names while the Mac restarts or waits for you to log in after a power cut. Some devices use both servers at once, so a small share of lookups skips ad blocking. That is the accepted price of FileVault (J14). No public resolver is handed out any more, and IPv6 no longer advertises the provider’s DNS, which were the two ways around filtering that the audit found.

UniFi Settings > Networks, for each of Default, Servers, IoT, Trusted and Surveillance (not Work, the work network, which keeps the gateway’s DNS: J30, and not Neighbor_WiFi or Standby):

Setting Value
DHCP DNS Server Manual: 10.0.2.5, then that network’s own gateway (10.0.N.1)
IPv6 > DNS Server (or RDNSS) Manual and empty, or off. Clients then use the IPv4 resolver for both families

Leave Neighbor_WiFi on its public resolvers, and Standby without DHCP.

Then the machines with fixed settings:

Mac

Terminal window
networksetup -setdnsservers Ethernet 10.0.2.5 10.0.5.1
  • Every device from your list in step 2.6 that has 10.0.2.2 typed in by hand: change it to 10.0.2.5.
  • The SD-WAN spoke (10.1.1.0/24) asks the Pi-hole at 10.0.2.2 today. On that site’s console, Settings > Networks > its LAN > DHCP DNS Server: 10.0.2.5, then its own gateway. If you skip this, that site loses name resolution when the Pi-hole stops.
  • The existing home VM at 10.0.5.20 (restore path): ssh admin@10.0.5.20 "printf 'nameserver 10.0.2.5\nnameserver 10.0.5.1\n' | sudo tee /etc/resolv.conf".

Clients switch when they renew their lease. Turn Wi-Fi off and on to hurry a phone. Wait one day, then stop the old resolver (restore path):

NAS Container Manager > Container: stop pihole and dnscrypt-proxy, and turn their auto-restart off. Keep them for two weeks.

Verify.

Terminal window
scutil --dns | grep -m2 nameserver # 10.0.2.5 first
ssh infra 'docker logs adguardhome 2>&1 | tail -3' # no error

In AdGuard’s Query Log, clients from several networks appear (10.0.5.x, 10.0.4.x, 10.0.1.x). On an iPhone on the main Wi-Fi, Settings > Wi-Fi > (i) > Configure DNS lists 10.0.2.5 and 10.0.5.1. Before you stop the Pi-hole, its own query log shows almost no client left.

Rollback. Set DHCP DNS Server back to its previous value on each network (your screenshots from step 2.6), start the two NAS containers again, and networksetup -setdnsservers Ethernet 10.0.5.1.

Why. Prometheus collects numbers, Loki collects log lines, Grafana shows both. The exporters are the same ones that ran on the NAS, with the same job names, because the health rules select on those names.

infra

Terminal window
cd /srv/stack && docker compose --profile monitoring up -d
docker compose --profile monitoring ps --format 'table {{.Name}}\t{{.Status}}'

Verify. Eleven containers show Up: adguardhome, prometheus, blackbox-exporter, node-exporter, cadvisor, snmp-exporter, unpoller, loki, alloy, grafana, caddy. Then, from the Mac:

Terminal window
curl -s http://10.0.2.5:9090/api/v1/targets | jq -r '.data.activeTargets[] | "\(.health)\t\(.labels.job)\t\(.labels.instance)"' | sort

Everything is up except the targets that do not exist yet: http://10.0.5.2:8123 and https://10.0.5.2:10443 (chapters 7 and 8), the Insights Plus health URL (part D), and synology on the from-scratch path until step 11.9. On the restore path synology is up at once, because the NAS already answers SNMP at 10.0.2.2.

Rollback. docker compose --profile monitoring down stops everything except what you start again with docker compose up -d adguardhome. Run that second command straight away: down stops DNS too.

Why. UnPoller is the source of every UniFi number (speed, clients, Wi-Fi retries). It polls once a minute with DPI off, because polling every 10 seconds was the prime suspect for the UDM Pro’s CPU climbing until a reboot.

infra

Terminal window
docker logs unpoller 2>&1 | tail -5
curl -s http://10.0.2.5:9090/api/v1/query --data-urlencode 'query=unifipoller_controller_up' | jq -r '.data.result[0].value[1]'

Verify. The log shows UniFi Measurements Exported with a count of sites, clients and devices, and the query prints 1.

Rollback. If it prints 0 or the log says 401, the account of step 3.6 is wrong: check the item UniFi local admin unpoller, run vm-push.sh infra, then docker compose --profile monitoring up -d unpoller.

6.14 The health rules, and what they still expect

Section titled “6.14 The health rules, and what they still expect”

Why. home-overview.rules.yml turns raw numbers into the states the Home panel shows (Healthy, Warning, Problem). The file is generated by the ha-home-panel project and still describes the old layout. Loading it as it is works, and this step tells you which states will read Unknown until it is regenerated.

Scope in the rules Expects After this chapter
Internet blackbox probes, job names unchanged Works
UniFi unifipoller, blackbox-unifi Works
Synology SNMP job synology at 10.0.2.2 Works on the restore path now, on the from-scratch path after step 11.9
DNS blackbox-dns plus the two Pi-hole exporters Half: the probe works, the Pi-hole exporter sources are gone, so the scope reads Unknown
Pi-hole job pihole Unknown. Shown as “Can’t check Ad blocking right now”
Containers cAdvisor on the NAS with the NAS container names, web checks on 10.0.2.2 ports Unknown or Problem: the names and addresses changed

The fix belongs in ha-home-panel: regenerate the rules with the Pi-hole scope removed (the AdGuard Home integration in Home Assistant gives the blocked share), the Containers list set to the names of steps 6.12 and 7.6, and the web checks pointed at the addresses in vm/infra/prometheus/prometheus.yml. It is listed in chapter 16 as an open item. Nothing else in this guide depends on it.

infra

Terminal window
curl -s http://10.0.2.5:9090/api/v1/rules | jq -r '.data.groups | length'
curl -s http://10.0.2.5:9090/api/v1/query --data-urlencode 'query=home:scope_state' | jq -r '.data.result[] | "\(.metric.scope)\t\(.value[1])"'

Verify. The first command prints a number above 0 (the rule file loaded), and the second lists one line per scope.

Rollback. None needed: the rules only compute.

6.15 Trust the local certificate authority

Section titled “6.15 Trust the local certificate authority”

Why. Grafana and Insights Plus are served over HTTPS by Caddy with a certificate from its own small authority. Trusting that authority on the Mac removes the browser warning, and nothing leaves the LAN.

Mac

Terminal window
ssh infra 'docker exec caddy cat /data/caddy/pki/authorities/local/root.crt' > ~/infra-migration/caddy-root.crt
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/infra-migration/caddy-root.crt

Verify. curl -sI https://grafana.home.arpa:8444/login | head -1 prints HTTP/2 200 with no certificate error.

Rollback. sudo security delete-certificate -c "Caddy Local Authority - 2026 ECC Root" (the exact name shows in Keychain Access under System).

Why. Grafana is where you read history: the health dashboard, and every log line of the house beside the metrics.

Mac Open https://grafana.home.arpa:8444. Sign in as admin with op read "op://Infrastructure/Grafana admin/password" | pbcopy. Connections > Data sources already lists Prometheus and Loki.

Restore. Dashboards > New > Import, once per JSON file in ~/infra-migration/backups/grafana/. Choose the Prometheus data source when asked.

From scratch. Import $INFRA/services/monitoring/grafana/home-overview.json the same way.

Verify. The Home Overview dashboard draws the Internet and UniFi cards with data. In Explore, choose Loki, run {host="infra"}: log lines from this VM’s containers appear. Run {job="unpoller"} or browse the labels: UniFi events arrive within a few minutes.

Rollback. Delete the dashboard. Nothing else depends on it.

6.17 Start it and create the admin at once

Section titled “6.17 Start it and create the admin at once”

Why. Insights Plus reads the router’s own log (firewall hits, DHCP, Wi-Fi, VPN) and makes it searchable, with the country and reputation of outside addresses. Two rules keep it safe: login is on (AUTH_ENABLED=true, because without it anyone reaching the page could make the app send its stored UniFi key elsewhere), and it is only reachable through Caddy over HTTPS. Until the first account exists, whoever opens the page first becomes admin, so do both halves of this step in one go.

infra

Terminal window
cd /srv/stack && docker compose --profile monitoring --profile insights up -d
docker logs -f unifi-log-insight # wait for the database init and the GeoLite2 download, then Ctrl-C

Mac Open https://insights.home.arpa:8443 and create the admin account. Store it:

Terminal window
op item create --vault Infrastructure --category login --title "Insights Plus admin" \
username=admin --generate-password='letters,digits,32' url=https://insights.home.arpa:8443

Generate the item first and paste its password into the form. In the setup wizard choose the UniFi API path. It finds the WAN and the VLANs by itself.

Never change SECRET_KEY (the 1Password field secret key): it encrypts what the app stores, and a new value makes that unreadable.

Verify. curl -s https://insights.home.arpa:8443/api/health answers with a healthy status, and the dashboard shows the networks by name.

Rollback. docker compose --profile insights rm -sf insights && docker volume rm unifi-log-insight-pgdata.

Why. The UDM Pro pushes its log as syslog. Only its address (10.0.2.1) is accepted on that port (step 6.6).

UniFi Settings > Control Plane > Integrations > Activity Logging (Syslog): SIEM Server, server 10.0.2.5, port 514. Enable Firewall Default Policy, Security Detections, Clients and VPN.

In Insights Plus, Firewall Syslog Manager lists the policies. The insights account is view-only (step 3.6), so turn logging on in UniFi itself for the policies you care about: open the policy and tick Syslog Logging. After chapter 10, do that for the Block policies.

Verify. ssh infra 'sudo timeout 20 tcpdump -ni enp0s1.2 udp port 514 -c 3' shows packets from 10.0.2.1, and the Insights Plus dashboard counts events within a minute.

If packets arrive from another source address, change UDM= in vm/infra/firewall.sh, push, and run step 6.6 again. If the dashboard counts packets but parses nothing, turn the SIEM setting off, restart the gateway, and turn it on again: the project documents this for Network 10 and later.

Rollback. Set Activity Logging back to off.

Why. Two Prometheus servers polling the UDM Pro double its load, and the old dashboards would keep showing stale data. Restore path only.

NAS Container Manager > Project > monitoring: Stop. Then Container: stop homepage and uptime-kuma, and turn auto-restart off on all of them. Do not delete anything yet: chapter 11 archives and removes them after two clean weeks.

Verify. curl -s -m 3 http://10.0.2.2:9090/-/healthy fails, and curl -s http://10.0.2.5:9090/-/healthy answers Prometheus Server is Healthy.

Rollback. Start the project again on the NAS.

6.20 Commit, and check memory after a week

Section titled “6.20 Commit, and check memory after a week”

Why. The pinned versions and any change you made belong in the repository. The memory figures in this guide are estimates until measured.

Mac

Terminal window
cd $INFRA && git status --short && git push

One week later:

Terminal window
ssh infra 'free -m; docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}"'

Verify. available memory stays above 800 MB. If it does not, raise the VM to 5120 MB in UTM (stop it with ssh infra sudo poweroff first).

Rollback. None needed.

Every device in the house resolves names through AdGuard Home at 10.0.2.5, with the gateway as fallback. Prometheus, Grafana and Loki run on the VM, UniFi events and the router’s log are searchable, and the NAS no longer serves DNS or monitoring. Home Assistant’s address is still probed in vain: the next chapter brings it.