A simple, go-based DNS resolver/caching server
Go to file
bigeagle 3df6ec09f3 Specify server in server-list-file 2015-02-04 16:21:08 +08:00
examples Specify server in server-list-file 2015-02-04 16:21:08 +08:00
.gitignore add IPv6 support 2015-02-03 20:33:54 +08:00
README.md Fix some spelling and grammar in README.md 2014-12-08 10:52:59 -07:00
cache.go locks 2013-12-12 10:31:26 -02:00
godns_test.go add benchmark test 2013-07-25 12:32:57 +08:00
handler.go only cache successful lookups 2015-02-03 23:20:36 +08:00
hosts.go redis-enable is now in hosts 2015-02-03 23:09:20 +08:00
hosts_test.go dnsmasq style domain specific server supported 2015-02-03 22:53:57 +08:00
main.go add benchmark test 2013-07-25 12:32:57 +08:00
resolver.go Specify server in server-list-file 2015-02-04 16:21:08 +08:00
server.go first commit 2013-07-23 19:10:38 +08:00
settings.go Specify server in server-list-file 2015-02-04 16:21:08 +08:00
sfx_tree.go dnsmasq style domain specific server supported 2015-02-03 22:53:57 +08:00
sfx_tree_test.go dnsmasq style domain specific server supported 2015-02-03 22:53:57 +08:00

README.md

GODNS

A simple and fast dns cache server written by go.

Similar to dnsmasq ,but support some difference features:

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

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

  • Cache records save in memory or redis configurable

Installation & 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
    

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

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"

redis hosts

This is a special requirment in our system. Must maintain a global hosts configuration, and support update the hosts record from other remote server. so "redis-hosts" will be supported, and 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.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 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