Register lxcs from proxmox into dnsmasq

Hi all,

I run proxmox, and give the machines names that I want to appear in the local DNS.

I've searched the docs and forums, but don't see an official solution.

ChatGPT sats, Pi-hole's official API doesn't yet support adding Local DNS Records directly. But if you're using Pi-hole v5.0+, you can directly modify /etc/pihole/custom.list and then reload DN

So, I was thinking of the following.. what do you think?

#!/bin/bash

# Config
PIHOLE_HOST="pi.hole.local"        # or IP of your Pi-hole
PIHOLE_USER="pi"                   # SSH user on Pi-hole
PIHOLE_CUSTOM_LIST="/etc/pihole/custom.list"
TMPFILE="/tmp/custom.list"

# Create a temp file with updated DNS entries
> "$TMPFILE"
for cid in $(pct list | awk 'NR>1 {print $1}'); do
  name=$(pct config "$cid" | grep ^hostname | awk '{print $2}')
  ip=$(pct exec "$cid" -- hostname -I | awk '{print $1}')
  echo "$ip    $name.lan" >> "$TMPFILE"
done

# Send to Pi-hole and reload DNS
scp "$TMPFILE" "$PIHOLE_USER@$PIHOLE_HOST:/tmp/custom.list"
ssh "$PIHOLE_USER@$PIHOLE_HOST" "sudo mv /tmp/custom.list $PIHOLE_CUSTOM_LIST && sudo pihole restartdns"

echo "✔️ Updated Pi-hole DNS with LXC entries."

Thanks, Martin

ChatGPT just suggested also:

:test_tube: Want to Try Another Approach?

If you're interested in making it even more dynamic:

  • Use dnsmasq on Proxmox directly and point Pi-hole to it as upstream.
  • Or run avahi-daemon in LXCs for .local mDNS resolution without static DNS.