- do not use
bind 127.0.0.1
when running from a container, as it prevents the requests from being handled.
Last active
November 26, 2021 06:10
-
-
Save gbraad/41d69ed4e328102540e824cf5284780b to your computer and use it in GitHub Desktop.
Create a DNS Responder using CoreDNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.: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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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