Simple and tiny DNS server written in Golang for filtering domains and speed up name resolution functionality.
Core features:
forward and cache dns queries
block domain names with regex.
Prerequisites: Golang + Git
Installing for windows - linux - freebsd and macos. (linux is recommended)
Clone the code form Github or Snix servers.
# git clone https://slc.snix.ir/snix/nanodns.git # Snix
# git clone https://github.com/khokooli/nanodns.git # Github
# cd nanodns
# go get -v
# go build
# ./nanodns
2020/07/31 05:11:29 upstream dns: 1.1.1.1:53 connection udp
2020/07/31 05:11:29 dns listen on: 0.0.0.0:53 connection udp
2020/07/31 05:11:29 load banned domains from: noacc.txt
If you want to build this for other device architectures (like Mikrotik, Raspberry pi) follow this.
Build for Mikrotik RB 2011 UIAS-IN runing on OpenWRT: (Mipsbe CPU)
# cd nanodns
# GOOS=linux GOARCH=mips GOMIPS=softfloat go build
# scp nanodns [email protected]:/root/
After all connect to your device and run the nanodns binary.
Building for Raspberry pi: (ARM64 CPU's)
cd nanodns
GOARCH=arm64 GOOS=linux go build
# ./nanodns -h
Usage of ./nanodns:
-fakeadd string
an ip to send back for filtered domains <ipaddr> (default "127.0.0.1")
-filter string
filtered domains <filename> - regex is supported (default "noacc.txt")
-loaddr string
dns server listen address <ipaddr:port> (default "0.0.0.0:53")
-loconn string
dns server connection type <udp|tcp> (default "udp")
-upaddr string
upsteam dns server to connect <ipaddr:port> (default "1.1.1.1:53")
-upconn string
upsteam dns connection type <udp|tcp> (default "udp")
You can use regex for blocking domain names, create a file like noacc.txt
in nanodns
directory.
For blocking all com
and example.net
put the following in noacc.txt
Regex Test Tool Online
^([a-z0-9]+[.])*com.$
example.net.
Block all domains if contain following words:
advertise
, torrent
or hack
^(torrent|hack|advertise).*$
Block any domain except google.com
and snix.ir
^((?!google[.]com[.]|snix[.]ir[.]).)*$
Notes about regex in Golang:
Please note that if your regex string contain escape character '\'
char, put another backslash befor it.
Read more about Escape Character.
^\babc\b.*$ ---> wrong
^\\babc\\b.*$ ---> it's ok
So if you interested to learn Golang follow my Instagram Account, Thanks.