Synchronise records founds through docker labels with pihole's custom dns and cname records.
- Navigate to the api tab in your pihole settings
- Click the
Show API token
button - Copy the
Raw API Token
- Use this as
PIHOLE_TOKEN
cli
docker run \
-l "pihole.custom-record=[[\"pihole-dns-shim.lan\", \"127.0.0.1\"]]" \
-e PIHOLE_TOKEN="" \
-e PIHOLE_API="http://pi.hole:8080/admin/api.php" \
-e STATE_FILE="/state/pihole.state" \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
theonlysinjin/docker-pihole-dns-shim
docker-compose.yml
services:
pihole-dns-shim:
container_name: "pihole-dns-shim"
image: theonlysinjin/docker-pihole-dns-shim
restart: unless-stopped
labels:
- pihole.custom-record=[["pihole-dns-shim.lan", "127.0.0.1"]]
environment:
PIHOLE_TOKEN: "${PIHOLE_TOKEN}"
PIHOLE_API: "${PIHOLE_API}"
# LOGGING_LEVEL: "DEBUG"
# STATE_FILE: "/state/pihole.state"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
Add records to pihole by labelling your docker containers, you can add as many labels(records) to individual containers as you need.
An example of the (json-encoded) label is as follows:
pihole.custom-record:
- ["pihole-dns-shim.lan", "127.0.0.1"]
- ["pihole-dns-shim.lan", "www.google.com"]
as a docker label:
"pihole.custom-record=[[\"pihole-dns-shim.lan\", \"127.0.0.1\"], [\"pihole-dns-shim.lan\", \"www.google.com\"]]"
You can turn on extra logging by setting the log level to DEBUG,
Set an env variable in the container with LOGGING_LEVEL="DEBUG"
Make a GET request to the following endpoints.
Replace the parts of the url that are in uppercase.
Add new DNS record
http://pi.hole:8080/admin/api.php?customdns&action=add&ip=IPADDRESS&domain=DOMAIN&auth=XXX
Delete existing DNS record
http://pi.hole:8080/admin/api.php?customdns&action=delete&ip=IPADDRESS&domain=DOMAIN&auth=XXX
List existing DNS records
http://pi.hole:8080/admin/api.php?customdns&action=get&auth=XXX
Add new CNAME record
http://pi.hole:8080/admin/api.php?customcname&action=add&domain=DOMAIN&target=TARGET&auth=XXX
Delete existing CNAME record
http://pi.hole:8080/admin/api.php?customcname&action=delete&domain=DOMAIN&target=TARGET&auth=XXX
List existing CNAME records
http://pi.hole:8080/admin/api.php?customcname&action=get&auth=XXX