How to create personal DNS server

I want to create my personal DNS server on my local machine. Because my country is a joke and I often have problems with access to international DNS servers like 1.1.1.1 etc.

private linux DNS server with networks and Net security|lower


LOCAL DNS ON LINUX UBUNTU

systemd-resolved

1. Configuration in /etc/resolv.conf

2. To cache DNS for 5 years in /etc/systemd/resolved.conf

CacheTTLSec=157680000

NegativeCacheTTLSec=157680000

3. It is better to use Local DNS server like dnsmasq or unbound. But they will be in conflict with systemd-resolved.

sudo systemctl stop systemd-resolved

sudo systemctl disable systemd-resolved

sudo systemctl mask systemd-resolved  # Prevent it from auto-starting

4. Finally after trying all small DNS servers I ve realized on Linux Mint available only old versions which doesn't support persistent cache which I need. I've decided to use systemd-resolved.

4.1. Configuration is /etc/systemd/resolved.conf

4.2. Create custom dns-warmer.service at /etc/systemd/system/dns-warmer.service

4.3. systemd-resolved is old on Linux Mint and doesn't support configuration command DNSStubListenerExtra. I am so tired of this Linux Mint. Newer EVER install this crap on your machine.

 

dnsmasq

0. I will install this server on one of my old local machine in local network.

1. Installation $ sudo apt install dnsmasq

1.1. I got Failed to start dnsmasq - A lightweight DHCP and caching DNS server. // $ sudo systemctl stop systemd-resolved

1.2. $ sudo systemctl start dnsmasq

1.2.1. When I've started dnsmasq it starts to consume 100% of CPU.

1.2.1.1. In /etc/dnsmasq.conf >

server=8.8.8.8

server=1.1.1.1

1.3. In dnsmasq.conf option cache-file= crashes the service.

1.3.1. Probably version 2.80 is too old and doesn't support cache-file option. Renew to 2.85 or newer.

1.3.2. I just cannot renew to 2.86 because MINT linux currently doesn't have dependencies even if you download .deb 

1.3.3. I will try alternatives to dnsmasq.

2. I will upgrade Linux MINT to be able install 2.85 dnsmasq.

3. dnsmasq doesn't support persistent cache at all. 

4. Finally I decided to use dnsmasq on my old laptop without often reboots which will be equivalent of persistent cache.

listen-address=192.168.1.55,127.0.0.1

bind-interfaces

server=8.8.8.8          # Upstream DNS 1

server=1.1.1.1          # Upstream DNS 2

# Cache settings

cache-size=10000         # Number of records to cache (default 150)

local-ttl=2592000        # 30 days for local names

min-cache-ttl=2592000    # Minimum TTL: 30 days (2,592,000 sec)

max-cache-ttl=2592000    # Maximum TTL: 30 days (overrides server TTL)

4.1. It is caching nothing. /var/cache/dnsmasq/dnsmasq.cache is empty.

5. This piece of crap server doesn't cache DNS queries according to ttl. I don't understand what was the poin to develop this crap at all?

 

Unbound

1. $ sudo apt install unbound

2. To config $ sudo nano /etc/unbound/unbound.conf

3. I need at least 1.13.0 version to support persistent caching.

3.1. I need some alternative which Linux Mint will support out of the box. like PDNSD.

4. Unbound doesn't support persistent cache.

5. Check configuration sudo unbound-checkconf

5.1. $ sudo unbound-checkconf shows fatal error: auto-trust-anchor-file /var/lib/unbound/root.key doesn't exist

5.1.1. sudo unbound-anchor -a "/var/lib/unbound/root.key" // helps

5.2. sudo systemctl status unbound shows error can't bind socket: Permission denied

 

 

 

 

 

 

 

PDNSD

1. $ sudo apt install pdnsd // There is no pdnsd in depository

2. Download .deb file from launchpad.net version 1.2.9a-par

3. /etc/pdnsd.conf

global {

    perm_cache=2048;              # enable permanent cache (in entries)

    cache_dir="/var/cache/pdnsd"; # on-disk cache location

    max_ttl=604800;               # cache up to 1 week (in seconds)

    server_port = 53;

    server_ip = "127.0.0.1";      # listen on localhost

    run_as = "pdnsd";

    status_ctl = on;

    paranoid = on;

}

server {

    label = "MyResolver";

    ip = 8.8.8.8, 8.8.4.4;        # upstream DNS servers

    port = 53;

    timeout = 60;

    interval = 900;

    purge_cache = off;

    caching = on;

}

4. It is caching literally nothing. So I don't know solution with persistent cache.

5. To check conf file: $ sudo pdnsd -d -v2

6. sudo systemctl status pdnsd shows active(exited) but sudo ss doesn't show 53 port is used and dig @127.0.0.1 shows communication error

6.1 To conf file, global section add daemon = on; 

 

 

pdns-recursor

1. $ sudo apt install pdns-recursor

2. Configuration $ sudo nano /etc/powerdns/recursor.conf

3. get SERVFAIL // dnssec = off in configuration file

 

 

BIND 9

1. $ sudo apt install bind9

2. $ sudo systemctl status bind9 shows:

timed out resolving './DNSKEY/IN': 8.8.8.8#53

managed-keys-zone: Unable to fetch DNSKEY set '.': SERVFAIL

2.1. It is because of dnssec-validation auto string in /etc/bind/named.conf.options file

3. Bind9 naturaly doesn't support persistent cache but I will do work around scriptы.

3.1. Dump Service (runs on shutdown) /usr/local/bin/bind-dump-cache

3.2. Load Service (runs after startup) /usr/local/bin/bind-load-cache

3.3. And create services /etc/systemd/system/bind-load.service and bind-dump.service

3.4. It actually creates scripts the after each reboot request global DNS to fill the file which is not suited for me. I need just real persistance. I will upgrade Linux MINT to be able install 2.85 dnsmasq.

 

 

sudo apt-get install bind9utils

 

DNSCrypt

1. sudo apt install dnscrypt-proxy

2. In /etc/resolv.conf

nameserver = 127.0.0.1

options edns0

3. in /etc/dnscrypt-proxy/dnscrypt-proxy.toml

listen_addresses = [ ]

4. I service doesn't has permission to bind to port change port to 5353 in config file