Skip to content

Instantly share code, notes, and snippets.

@marjamis
Last active September 24, 2022 04:26
Show Gist options
  • Save marjamis/9e5b9264b952ba8928bbf4734f043f37 to your computer and use it in GitHub Desktop.
Save marjamis/9e5b9264b952ba8928bbf4734f043f37 to your computer and use it in GitHub Desktop.
CoreDNS Example

custom_coredns

Testing

To test you can run the below samples against your coredns, assuming the default configurations I've customised are used.

dig @127.0.0.1 -p 10053 ip-172-55-55-66.us-west-1.compute.internal
dig @127.0.0.1 -p 10053 CH version.bind TXT
dig @127.0.0.1 -p 10053 example.org

Future plans?

  • This example currently uses file for the zones but can be flipped to redis and sql in the future if I decide I want to build my own coredns binary.
(global_configurations) {
log {
class all
}
errors
cache
prometheus :9153
}
coredns.io:5300 {
import global_configurations
file /root/coredns/zones/db.coredns.io
}
example.io:53 {
import global_configurations
file /root/coredns/zones/db.example.io {
reload 10s
}
# erratic {
# delay
# }
}
amazonaws.com:53 {
forward . 9.9.9.9
}
testing.com:53 {
forward . /etc/resolv.conf
}
example.org {
whoami
}
.:53 {
import global_configurations
reload
ready
whoami
health
# kubernetes
forward . 8.8.8.8
chaos CustomVersion NormalAuthors
rewrite name foo.example.com amazon.com
# This replicates the behaviour of Amazons VPC DNS, which returns the ip address of an instance from the hostname in the query. Note: in this case the <az>.compute.internal component of the query is essentially ignored.
template IN A {
match ^ip-(?P<a>[0-9]*)-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*).*.$
answer "{{ .Name }} 60 IN A {{ .Group.a }}.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"
fallthrough
}
}
; coredns.io zone
coredns.io IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
new.coredns.io IN CNAME google.com
; example.io zone
example.io IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082543 7200 3600 1209600 3600
again.example.io. IN CNAME amazon.com.
test.example.io. IN A 172.31.0.1
example.io. IN A 169.254.0.1
test2.example.io. IN A 128.9.9.1
test3.example.io. IN A 192.168.1.1
version: '3.7'
services:
coredns:
image: coredns/coredns
container_name: coredns
restart: always
command: -conf /root/coredns/Corefile
volumes:
- ./zonefiles/:/root/coredns/zones/:ro
- ./Corefile:/root/coredns/Corefile:ro
ports:
- 5300:5300/udp
- 9153:9153/udp
- 8181:8181
- 10053:53/udp
- 8880:8080
networks:
- general
networks:
general:
driver: bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment