A simple, go-based DNS resolver/caching server
Go to file
Tyler ba0bffed6d
continuous-integration/drone/push Build is passing Details
We need gcc I guess...
2021-04-15 01:10:13 -04:00
api API Implementation, patches 2021-04-15 00:41:06 -04:00
cache Redo settings a bit, move a lot of init logic to main.go 2020-01-25 13:48:26 -05:00
etc Changes to allow host "Set" to be standard, providers being able to use other query types, cache all responses, etc. 2020-02-07 22:38:22 -05:00
hosts Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml. 2021-04-15 01:04:58 -04:00
resolver Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml. 2021-04-15 01:04:58 -04:00
settings Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00
utils Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml. 2021-04-15 01:04:58 -04:00
.drone.yml We need gcc I guess... 2021-04-15 01:10:13 -04:00
.gitignore Fix serverlist issues 2019-09-26 00:43:17 -04:00
.gitlab-ci.yml Manifest 2018-08-31 21:34:14 -04:00
Dockerfile Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00
LICENSE godns under the MIT license 2015-05-25 17:18:57 +08:00
README.md Semicolon separate multiple domain list files and update examples 2018-02-01 19:22:45 +08:00
go.mod Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00
go.sum Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00
godns_test.go CodeReviewComments#imports 2015-02-10 17:04:57 +08:00
handler.go API Implementation, patches 2021-04-15 00:41:06 -04:00
main.go Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml. 2021-04-15 01:04:58 -04:00
manifest.yml Fix registry url 2019-06-02 17:21:45 -04:00
server.go Add bolt provider, rewrite hosts, start of api, start of update via nsupdate 2021-04-14 23:42:24 -04:00

README.md

GODNS

A simple and fast dns cache server written by go.

Similar to dnsmasq, but supports some difference features:

  • Keep hosts records in redis and the local file /etc/hosts

  • Auto-Reloads when hosts configuration is changed. (Yes, dnsmasq needs to be reloaded)

Installation & Running

  1. Install

     $ go get github.com/kenshinx/godns
    
  2. Build

     $ cd $GOPATH/src/github.com/kenshinx/godns 
     $ go build -o godns 
    
  3. Running

     $ sudo ./godns -c ./etc/godns.conf
    
  4. Test

     $ dig www.github.com @127.0.0.1
    

Use godns

	$ sudo vi /etc/resolv.conf
	nameserver #the ip of godns running

Configuration

All the configuration in godns.conf is a TOML format config file.
More about Toml :https://github.com/mojombo/toml

resolv.conf

Upstream server can be configured by changing file from somewhere other than "/etc/resolv.conf"

[resolv]
resolv-file = "/etc/resolv.conf"

If multiple namerservers are set in resolv.conf, the upsteam server will try in a top to bottom order

server-list-file

Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq.

server=/google.com/8.8.8.8

More cases please refererence dnsmasq-china-list

cache

Only the local memory storage backend is currently implemented. The redis backend is in the todo list

[cache]
backend = "memory"   
expire = 600  # default expire time 10 minutes
maxcount = 100000

hosts

Force resolve domain to assigned ip, support two types hosts configuration:

  • locale hosts file
  • remote redis hosts

hosts file

can be assigned at godns.conf,default : /etc/hosts

[hosts]
host-file = "/etc/hosts"

Hosts file format is described in linux man pages. More than that , *. wildcard is supported additional.

redis hosts

This is a special requirment in our system. Must maintain a global hosts configuration, and support update the host records from other remote server. Therefore, while "redis-hosts" be enabled, will query the redis db when each dns request is reached.

The hosts record is organized with redis hash map. and the key of the map is configured.

[hosts]
redis-key = "godns:hosts"

Insert hosts records into redis

redis > hset godns:hosts www.test.com 1.1.1.1

Compared with file-backend records, redis-backend hosts support multiple A entries.

redis > hset godns:hosts www.test.com 1.1.1.1,2.2.2.2

Benchmark

Debug close

$ go test -bench=.

testing: warning: no tests to run
PASS
BenchmarkDig-8     50000             57945 ns/op
ok      _/usr/home/keqiang/godns        3.259s

The result : 15342 queries/per second

The test environment:

CentOS release 6.4

  • CPU:
    Intel Xeon 2.40GHZ 4 cores

  • MEM:
    46G

Web console

Joke: A web console for godns

https://github.com/kenshinx/joke

screenshot

joke

Deployment

Deployment in productive supervisord highly recommended.


[program:godns]
command=/usr/local/bin/godns -c /etc/godns.conf
autostart=true
autorestart=true
user=root
stdout_logfile_maxbytes = 50MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/godns.log

TODO

  • The redis cache backend
  • Update ttl

LICENSE

godns is under the MIT license. See the LICENSE file for details.