Dnscache Loadbalancer

OS: Centos7

Add v6 address

/etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6ADDR=2001:DB8:ABC::53:1/64
IPV6_DEFAULTGW=2001:DB8:ABC::1

Install Packages

yum -y install make patch gcc wget cpan

Install Daemontools

links -source http://whbox.webhuset.no/src/whinstall > /usr/local/sbin/whinstall
chmod 755 /usr/local/sbin/whinstall
whinstall qmail daemontools

/etc/systemd/system/daemontools.service

[Unit]
Description=DJB daemontools
After=sysinit.target

[Service]
ExecStart=/command/svscanboot
Restart=always

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable daemontools
systemctl start daemontools

djbdns cache server

Install

cd /usr/local/src
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
tar -zxvf djbdns-1.05.tar.gz
wget http://www.fefe.de/dns/djbdns-1.05-test28.diff.xz
wget https://raw.githubusercontent.com/pld-linux/djbdns/master/dnscache-1.05-multiple-ip.patch
unxz djbdns-1.05-test28.diff.xz
cd djbdns-1.05
echo "gcc -O2 -include /usr/include/errno.h" > conf-cc
patch -p1 < ../djbdns-1.05-test28.diff
patch -p1 < ../dnscache-1.05-multiple-ip.patch
make
make setup check
adduser gdnscache
adduser gdnslog
dnscache-conf gdnscache gdnslog /etc/dnscache 127.0.0.1
mkdir /var/log/dnscache
chown gdnscache:gdnslog /var/log/dnscache
chmod 770 /var/log/dnscache/
ln -s /etc/dnscache /service
svstat /service/dnscache
echo "127.0.0.1/::1/<eth0 ip>/<vip1>/<vip2>" > /service/dnscache/env/IP

Add root servers

cd /service/dnscache/root/servers/
dnsip `dnsqr ns . | awk "/^answer: \./ { print $5 }"` | grep -v ^$ > @

Add relays

Add ip addresses to subnets that can query the dnscache

cd /service/dnscache/root/ip
touch 127
touch ::1
touch <subnet>

Increase cache

Set cache to 300MB

echo 300000000 > /service/dnscache/env/CACHESIZE
echo 314572800 > /service/dnscache/env/DATALIMIT

Start service

svc -t /service/dnscache

Dnstop

install dnstop from epel-release

yum install -y epel-release
yum install -y dnstop
dnstop -p eth0 -l 9

Extra services