Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vi7/e41b07ff7d0fb845ac281cd940876e2a to your computer and use it in GitHub Desktop.
Save vi7/e41b07ff7d0fb845ac281cd940876e2a to your computer and use it in GitHub Desktop.
CoreDNS installer script for AsusWRT Merlin routers with config examples

CoreDNS installer script for AsusWRT Merlin

Installation

curl -sL https://gist.githubusercontent.com/vi7/e41b07ff7d0fb845ac281cd940876e2a/raw/coredns_installer_asuswrt_merlin.sh | sh && rm -f coredns_installer_asuswrt_merlin.sh

Running CoreDNS

Prepare Corefile and zone files (if needed) using examples from this gist, create launcher script /jffs/addons/coredns/coredns.sh with the following contents:

#!/usr/bin/env sh

nohup /jffs/addons/coredns/coredns --conf /jffs/etc/coredns/Corefile | logger -s -c -t coredns

Add following lines to the services start script /jffs/scripts/services-start:

logger -c -t services-start "Starting CoreDNS"
/jffs/addons/coredns/coredns.sh &

Disable builtin DNS server by creating /jffs/configs/dnsmasq.conf.add with port=0 inside (this does not disable DHCP)

Reboot router

#!/usr/bin/env sh
#############
### USAGE ###
#############
# 1. Modify version, arch and install path vars below if needed
#
# 2. SSH to the router, `cd /jffs` and run:
#
# curl -sL https://gist.githubusercontent.com/vi7/e41b07ff7d0fb845ac281cd940876e2a/raw/coredns_installer_asuswrt_merlin.sh | sh && rm -f coredns_installer_asuswrt_merlin.sh
VERSION="1.9.1"
ARCH="linux_arm64"
INSTALL_PATH="/jffs/addons/coredns"
mkdir -p "$INSTALL_PATH"
cd "$INSTALL_PATH"
if [ ! -f coredns ]
then
curl -LO "https://github.com/coredns/coredns/releases/download/v${VERSION}/coredns_${VERSION}_${ARCH}.tgz"
tar xzvf "coredns_${VERSION}_${ARCH}.tgz"
chmod a+x coredns
rm -vf "coredns_${VERSION}_${ARCH}.tgz"
echo "CoreDNS is installed to the $INSTALL_PATH"
else
echo "SKIPPING! CoreDNS seems to be present in the $INSTALL_PATH"
fi
#
# This Corefile example assumes:
# - port 53 is free on the router
# - zone files are created under '/jffs/etc/coredns/zones' (See examples in this gist)
#
# Create '/jffs/configs/dnsmasq.conf.add' with 'port=0'
# to disable builtin dnsmasq DNS server (this does not disable DHCP)
#
.:53 {
log {
class denial error
# uncomment to log everything
#class all
}
errors
loadbalance
prometheus 0.0.0.0:9153
reload
auto {
directory /jffs/etc/coredns/zones db\.(.*) {1}
}
# 91.239.100.100 - belongs to https://blog.uncensoreddns.org
forward . tls://91.239.100.100 tls://8.8.8.8 tls://8.8.4.4 tls://1.1.1.1 tls://1.0.0.1
}
$ORIGIN 1.168.192.in-addr.arpa.
$TTL 3h
@ IN SOA router.lan. root.lan. (
2021112801 ; serial in the format YYYYMMDD##
24h ; refresh after 24 hours
2h ; retry after 2 hours
1w ; expire after 1 week
1h ) ; minimum TTL of 1 hour
;
;
IN NS router.lan.
;
;
1 IN PTR router.lan.
2 IN PTR host1.lan.
3 IN PTR host2.lan.
$ORIGIN lan.
$TTL 3h
@ IN SOA router.lan. root.lan. (
2022012501 ; serial in the format YYYYMMDD## - !!! CHANGE ON EVERY ZONE UPDATE
24h ; refresh after 24 hours
2h ; retry after 2 hours
1w ; expire after 1 week
1h ) ; minimum TTL of 1 hour
;
;
IN NS router.lan.
;
;
router IN A 192.168.1.1
host1 IN A 192.168.1.2
host2 IN A 192.168.1.3
;
; Aliases
;
service-x IN CNAME host1.lan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment