godns/README.MD

145 lines
2.3 KiB
Plaintext
Raw Normal View History

2013-07-23 11:10:38 +00:00
GODNS
====
2013-07-25 04:32:57 +00:00
A simple and fast dns cache server written by go.
2013-07-23 11:10:38 +00:00
Similar as [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) ,but support some difference features:
2013-07-25 04:32:57 +00:00
* Keep hosts records in redis instead of the local file /etc/hosts
2013-07-23 11:10:38 +00:00
* Atuo-Reload when hosts configuration changed. (Yes,dnsmasq need restart)
* Cache records save in memory or redis configurable
2013-07-23 16:37:38 +00:00
2013-07-25 04:32:57 +00:00
## Install & Running
2013-07-24 16:09:07 +00:00
2013-07-25 04:32:57 +00:00
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
2013-07-24 10:29:38 +00:00
## Configuration
2013-07-23 16:37:38 +00:00
2013-07-24 02:52:59 +00:00
All the configuration on `godns.conf` a TOML formating config file.
2013-07-23 16:37:38 +00:00
More about Toml :[https://github.com/mojombo/toml](https://github.com/mojombo/toml)
2013-07-24 02:52:59 +00:00
#### 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
2013-07-23 16:37:38 +00:00
2013-07-24 10:29:38 +00:00
#### cache
2013-07-24 14:40:18 +00:00
Only the local memory storage backend implemented now. The redis backend is in todo list
2013-07-24 16:09:07 +00:00
```
[cache]
backend = "memory"
expire = 600 # default expire time 10 minutes
maxcount = 100000
```
2013-07-26 16:29:19 +00:00
#### 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"
```
2013-07-25 04:32:57 +00:00
## Benchmak
2013-07-26 16:10:17 +00:00
__Debug close__
2013-07-25 04:32:57 +00:00
```
$ go test -bench=.
testing: warning: no tests to run
PASS
2013-07-26 16:10:17 +00:00
BenchmarkDig-4 10000 202732 ns/op
ok _/Users/kenshin/workspace/gogo/godns 2.489s
2013-07-25 04:32:57 +00:00
```
2013-07-26 16:10:17 +00:00
The result : 4032 queries/per second
2013-07-25 04:32:57 +00:00
The enviroment of test:
MacBook Air
* CPU:
Inter Core i5 1.7G
Double cores
* MEM:
8G
2013-07-24 16:09:07 +00:00
## TODO
* The redis cache backend
* Update ttl
2013-07-24 10:29:38 +00:00
2013-07-23 16:37:38 +00:00