A simple, go-based DNS resolver/caching server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Tyler 764e326a4b Remove go.sum 3 years ago
etc Update go.mod/go.sum 3 years ago
.drone.yml Fix serverlist issues 3 years ago
.gitignore Fix serverlist issues 3 years ago
.gitlab-ci.yml Manifest 4 years ago
Dockerfile Add musl-dev for arm64 3 years ago
LICENSE godns under the MIT license 7 years ago
README.md Semicolon separate multiple domain list files and update examples 5 years ago
cache.go Fix serverlist issues 3 years ago
cache_memcached.go Redis caching 4 years ago
cache_memory.go Fix serverlist issues 3 years ago
cache_redis.go Fix pubsub, documentation, version 4 years ago
go.mod Update go.mod/go.sum 3 years ago
godns_test.go CodeReviewComments#imports 8 years ago
handler.go Redis caching 4 years ago
hosts.go Fix serverlist issues 3 years ago
hosts_file.go Fix serverlist issues 3 years ago
hosts_redis.go Fix serverlist issues 3 years ago
log.go Log Module 7 years ago
log_test.go Log Module 7 years ago
main.go CPU & MEM pprof output #12 7 years ago
manifest.yml Fix registry url 3 years ago
resolver.go Fix serverlist issues 3 years ago
server.go Fix serverlist issues 3 years ago
settings.go Fix pubsub, documentation, version 4 years ago
sfx_tree.go dnsmasq style domain specific server supported 8 years ago
sfx_tree_test.go Supplement test case, www.google.com should match /google.com/ 5 years ago
utils.go Fix serverlist issues 3 years ago
utils_test.go Extract public functions into utils 5 years ago



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 @

Use godns

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


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


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

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

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


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


More cases please refererence dnsmasq-china-list


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

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


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

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.

redis-key = "godns:hosts"

Insert hosts records into redis

redis > hset godns:hosts www.test.com

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

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


Debug close

$ go test -bench=.

testing: warning: no tests to run
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:

Web console

Joke: A web console for godns





Deployment in productive supervisord highly recommended.

command=/usr/local/bin/godns -c /etc/godns.conf
stdout_logfile_maxbytes = 50MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/godns.log


  • The redis cache backend
  • Update ttl


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