CoreDNS on macOS for Local Development

Brendan Thompson • 21 December 2021 • 4 min read

Over the years, I have tried a few different ways of managing DNS on my local laptop, sometimes with dnsmasq sometimes just with hosts file, and other times using public DNS. CoreDNS seems to be all the rage these days (as it should be), so I thought I would give that a try.

There are a few guides out there on how to configure CoreDNS with Docker or on your Kubernetes, but I was interested in running it all locally on my Mac.


  1. Homebrew

Installation & Setup#

  1. First off we let's install CoreDNS on our Mac

    brew install coredns
  2. Start the CoreDNS service

    sudo brew services start coredns
  3. Create a zone file for the DNS zone we want to use locally; this can be called anything

     $TTL 1h
     @                 IN  SOA (
                                       2020010510     ; Serial
                                       1d             ; Refresh
                                       2h             ; Retry
                                       4w             ; Expire
                                       1h)            ; Minimum TTL
     @                 IN  A
     @                 IN  NS
     ns                IN  CNAME   @

    This file contains the domain (or subdomain) that we want to use and a declaration of a name server record pointing to itself, this file uses resource records. It is worth reading up on the RDATA format required for SOA records, which you can do here.

  4. The following file we will create is the Corefile; this is where the magic happens

    . {
        forward .
    } {
      file /Users/brendanthompson/.config/coredns/

    Our file here is split into two server blocks, the first one . will match any DNS queries that do not match any domains listed in other server blocks. The second server block contains the domain and will parse through our zone file with the file plugin.

  5. Finally, we need to restart our CoreDNS service to see the results

    sudo brew services restart coredns
  6. Set our network interface to use our freshly minted DNS server

    1. With the command-line
      networksetup -setdnsservers Wi-Fi
    2. Using the GUI with the Network pane in System Preferences
      1. Select the network interface on the left-hand pane, and click on the Advanced button
      2. Select the DNS tab
      3. Add into the DNS Servers list on the left and click OK
      4. Click Apply
  7. Now that we have completed our setup, let's validate our configuration to ensure when we hit, it will resolve on our local DNS server. The following dig command can be used to check our DNS configuration

    bash dig

    If setup correct it will return the following:

    ; <<>> DiG 9.10.6 <<>>
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20882
    ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
    ;; WARNING: recursion requested but not available
    ; EDNS: version: 0, flags:; udp: 4096
    ;          IN  A
    ;; ANSWER SECTION:       3600    IN  A
    ;; AUTHORITY SECTION:       3600    IN  NS
    ;; Query time: 4 msec
    ;; SERVER:
    ;; WHEN: Tue Dec 21 10:09:04 AEDT 2021
    ;; MSG SIZE  rcvd: 110

    Further to this, we can see when using Safari that this blog post renders using our local address:

Closing Out#

Setting up to resolve using local DNS with CoreDNS mainly was just an experiment to see if it was possible to do. I am unsure if I will keep this running long term, but I am keen to continue playing around to see what value I can get out of running this locally.

Brendan Thompson

Principal Cloud Engineer

Discuss on Twitter