Skip to main content
  1. Our Guides/
  2. CoreDNS @ Wolfspyre Labs/
  3. 🏗️ Setting Up CoreDNS/
  4. Pi4 Soup to nuts/

④ Building CoreDNS

Build Packages
Unbound Libs
Setup Golang
[Build CoreDNS](#buildcoredns}
🐾

Package installations #

Some Packages that we are going to need for building:

apt-get install make build-essential git

Package Dependencies for unbound #

If you’re going to use the unbound resolver plugin, then you’ll need to install a few additional packages:
apt-get install libunbound-dev libunbound8 libevent-2.1-7

Setup Golang #

You will be able to The main Download page on the golang site1

https://go.dev/dl/go1.19.linux-arm64.tar.gz https://go.dev/dl/go1.19.1.linux-arm64.tar.gz

https://go.dev/doc/install

  • Remove any previous Go installation by deleting the /usr/local/go folder (if it exists).

  • Extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:
    $ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.linux-arm64.tar.gz
    (You may need to run the command as root or through sudo).

Warning
Do not untar the archive into an existing /usr/local/go tree. This is known to produce broken Go installations.
  • Add /usr/local/go/bin to the PATH environment variable.
    • You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):
cat <<EOF>/etc/profile.d/golang-path.sh
#!/usr/bin/env bash
export PATH=$PATH:/usr/local/go/bin
EOF
chmod +x /etc/profile.d/golang-path.sh
  • Validate it’s in your path by (after logging out and logging back in)
    inspecting the $PATH env var:
    One way to skin the cat: env|grep PATH
Note
Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.
  • Verify that you’ve installed Go by opening a command prompt and typing the following command: $ go version Confirm that the command prints the installed version of Go.
root@coredns-02:~# go version
go version go1.19 linux/arm64

Build CoreDNS #

Building CoreDNS is pretty simple, once all the pieces are in play.

First we’ll clone the repo #

get the coreDNS code local
REPO=https://github.com/coredns/coredns.git
REPO=https://gitlab.wolfspyre.io/mirrored_repos/coredns/coredns.git
cd /usr/src && git clone ${REPO} && cd /usr/src/coredns

Next, we’ll make our plugin.cfg changes #

get the coreDNS code local
cp plugin.cfg plugin.cfg.orig

Figure out where to split the plugin #

So… because the ordering of the plugins in the plugin.cfg file. Our additions fall just after the line containing template:template

splitting CoreDNS plugin.cfg file
wolf@coredns: /usr/src/coredns$ wc -l plugin.cfg
72 plugin.cfg
wolf@coredns: /usr/src/coredns$ head -53 plugin.cfg |tail -1
template:template
wolf@coredns: /usr/src/coredns$ tail -20 plugin.cfg|head -1
template:template

So, we now know that in this version of CoreDNS, our changes should be injected between lines 53 and 54

so lets do that horribly real quick:

CoreDNS Plugin.cfg manipulation
wolf@coredns: /usr/src/coredns$  cat plugin.cfg > plugin.cfg_orig
wolf@coredns: /usr/src/coredns$  head -53 plugin.cfg >wpl_plugin.cfg
wolf@coredns: /usr/src/coredns$  cat <<EOF>>wpl_plugin.cfg
git:github.com/miekg/coredns-git
mdns:github.com/openshift/coredns-mdns
netbox:github.com/oz123/coredns-netbox-plugin
unbound:github.com/coredns/unbound
finalize:github.com/tmeckel/coredns-finalizer
records:github.com/coredns/records
EOF
wolf@coredns: /usr/src/coredns$  tail -19 plugin.cfg  >> wpl_plugin.cfg
wolf@coredns: /usr/src/coredns$  cat wpl_plugin.cfg > plugin.cfg

SWEET!

So now we have our plugin file…
Populated with our changes…
Let’s build this puppy!

cd /usr/src/coredns; make clean;CGO_ENABLED=1 make

Yeah….
I know…
Somewhat anticlimactic.

🐾