A simple, go-based DNS resolver/caching server
Go to file
kenshin 69c00b85e4 add compiled executed file 2013-08-05 10:48:07 +08:00
bin add compiled executed file 2013-08-05 10:48:07 +08:00
README.md update benchmark enviroment and result. 2013-07-31 15:57:12 +08:00
cache.go cache add expire strategy 2013-07-25 00:09:07 +08:00
godns.conf append specification 2013-07-29 17:30:10 +08:00
godns_test.go add benchmark test 2013-07-25 12:32:57 +08:00
handler.go finally. fix hosts query 2013-07-26 18:54:19 +08:00
hosts.go syntax error. 2013-07-31 10:43:50 +08:00
main.go add benchmark test 2013-07-25 12:32:57 +08:00
resolver.go finally. fix hosts query 2013-07-26 18:54:19 +08:00
server.go first commit 2013-07-23 19:10:38 +08:00
settings.go finally. fix hosts query 2013-07-26 18:54:19 +08:00

README.md

GODNS

A simple and fast dns cache server written by go.

Similar as dnsmasq ,but support some difference features:

  • Keep hosts records in redis instead of the local file /etc/hosts

  • Atuo-Reload when hosts configuration changed. (Yes,dnsmasq need restart)

  • Cache records save in memory or redis configurable

Install & Running

  1. Install

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

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

     $ sudo ./godns -c godns.conf
    
  4. Use

     $ sudo vi /etc/resolv.conf
     nameserver 127.0.0.1
    

Configuration

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

resolv.conf

Upstream server can be configuration by change file from somewhere other that "/etc/resolv.conf"

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

If multi namerserver set at resolv.conf, the upsteam server will try in order of up to botton

cache

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

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

hosts

Force resolv 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"

redis hosts

This is a espeical requirment in our system. Must maintain a gloab hosts configuration, and support update the hosts record from other remote server. so "redis-hosts" is be supported, and will query the reids when each dns request reached.

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

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

Insert hosts records into redis

redis > hset godns:hosts www.sina.com.cn 1.1.1.1

Benchmak

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 enviroment of test:

CentOS release 6.4

  • CPU:
    Intel Xeon 2.40GHZ 4 cores

  • MEM:
    46G

TODO

  • The redis cache backend
  • Update ttl