..O Deniz's personal pages
/home /micro /about

Local dns server

April 1, 2020

I have a bunch of self hosted services running in containers on my docker host and it was getting pretty hard to keep track of which port was assigned to what. I wanted to setup an nginx proxy that would be the front end to all these services and also wanted to use human friendly addresses. The simple option would be to add all the hostnames to my etc/resolv.conf file but I use 5 different devices daily and some of them don’t even allow me to change that file. So I needed to run my own DNS server. The idea was to capture requests made to *.dendiz.lan and resolve them to my docker host and forward all other requests to my usual DNS servers.

DNS configs can be tricky but a project called coredns makes it very simple. The DNS itself is also a docker container which keeps things even cleaner. So I spun up a coredns container with following dns records file

$ORIGIN dendiz.lan.
@	3600 IN	SOA sns.dns.icann.org. noc.dns.icann.org. (
				2017042745 ; serial
				7200       ; refresh (2 hours)
				3600       ; retry (1 hour)
				1209600    ; expire (2 weeks)
				3600       ; minimum (1 hour)

	3600 IN NS a.iana-servers.net.
	3600 IN NS b.iana-servers.net.

*.dendiz.lan.     IN A
	      IN AAAA

and the config file

dendiz.lan:53 {
    file db.dendiz.lan

. {
    forward .

so any requests to dendiz.lan are resolved using my dns record file which uses a wildcard to resolve them to my docker hosts ip. I built the executable, created the docker image and started the container. Ran a bunch dig requests like

dig @localhost -p 53 www.dendiz.lan A

and got back an answer section. Nice! Next up creating the proxies… I found a nice project called nginx proxy manager that provides a web interface for creating proxy configs which also runs in a container. I installed that and created proxy hosts for all the services that I use and everything was looking good. one caveat with this setup is that I had manually set the DNS servers in the network settings on my devices. The solution to this issue was to configure my routers internet settings and put in my DNS server as the first server to use. Now all the devices that use DHCP can resolve my local domain.

Tags: #ops