Skip to content

Instantly share code, notes, and snippets.

@gbraad
Last active November 26, 2021 06:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbraad/41d69ed4e328102540e824cf5284780b to your computer and use it in GitHub Desktop.
Save gbraad/41d69ed4e328102540e824cf5284780b to your computer and use it in GitHub Desktop.
Create a DNS Responder using CoreDNS

Create a DNS Responder using CoreDNS

Notes

  • do not use bind 127.0.0.1 when running from a container, as it prevents the requests from being handled.
[Unit]
Description=CoreDNS DNS server
Documentation=https://coredns.io
After=network.target
[Service]
PermissionsStartOnly=true
PIDFile=/home/coredns/coredns.pid
LimitNOFILE=8192
User=coredns
WorkingDirectory=/home/coredns
ExecStartPre=/sbin/setcap cap_net_bind_service=+ep /opt/bin/coredns
ExecStart=/opt/bin/coredns -pidfile /home/coredns/coredns.pid -conf=/etc/coredns/Corefile
ExecReload=/bin/kill -SIGUSR1 $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
.:53 {
log
errors
#bind 127.0.0.1
proxy . /etc/resolv.conf
template IN A {
match "^(?P<a>[0-9]*)[.](?P<b>[0-9]*)[.](?P<c>[0-9]*)[.](?P<d>[0-9]*)[.](xip.io|nip.io|local|dev)[.]$"
answer "{{ .Name }} 60 IN A {{ .Group.a}}.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"
fallthrough
}
}
docker pull coredns/coredns:latest
docker run --name coredns \
-v $PWD/Corefile:/etc/coredns/Corefile \
-v /etc/resolv.conf:/etc/resolv.conf \
-p 127.0.0.1:53:53/tcp \
-p 127.0.0.1:53:53/udp \
-d coredns/coredns -conf /etc/coredns/Corefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment