diff --git a/README.md b/README.md index 3c801c3..b1b5b01 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,12 @@ Similar to [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html), but support 3. Running - $ sudo ./godns -c godns.conf + $ sudo ./godns -c ./etc/godns.conf 4. Test $ dig www.github.com @127.0.0.1 -More details about how to install and running godns can reference my [blog (Chinese)](http://blog.kenshinx.me/blog/compile-godns/) ## Use godns @@ -58,6 +57,12 @@ 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](https://github.com/felixonmars/dnsmasq-china-list) + #### cache diff --git a/etc/apple.china.conf b/etc/apple.china.conf new file mode 100644 index 0000000..820bf08 --- /dev/null +++ b/etc/apple.china.conf @@ -0,0 +1,46 @@ +server=/adcdownload.apple.com/114.114.114.114 +server=/appldnld.apple.com/114.114.114.114 +server=/cdn-cn1.apple-mapkit.com/114.114.114.114 +server=/cdn-cn2.apple-mapkit.com/114.114.114.114 +server=/cdn-cn3.apple-mapkit.com/114.114.114.114 +server=/cdn-cn4.apple-mapkit.com/114.114.114.114 +server=/cdn.apple-mapkit.com/114.114.114.114 +server=/cdn1.apple-mapkit.com/114.114.114.114 +server=/cdn2.apple-mapkit.com/114.114.114.114 +server=/cdn3.apple-mapkit.com/114.114.114.114 +server=/cdn4.apple-mapkit.com/114.114.114.114 +server=/cds.apple.com/114.114.114.114 +server=/cl1.apple.com/114.114.114.114 +server=/cl2.apple.com.edgekey.net.globalredir.akadns.net/114.114.114.114 +server=/cl2.apple.com.edgekey.net/114.114.114.114 +server=/cl2.apple.com/114.114.114.114 +server=/cl3.apple.com/114.114.114.114 +server=/cl4.apple.com/114.114.114.114 +server=/cl5.apple.com/114.114.114.114 +server=/gsp11-cn.ls.apple.com/114.114.114.114 +server=/gsp12-cn.ls.apple.com/114.114.114.114 +server=/gsp13-cn.ls.apple.com/114.114.114.114 +server=/gsp4-cn.ls.apple.com.edgekey.net.globalredir.akadns.net/114.114.114.114 +server=/gsp4-cn.ls.apple.com.edgekey.net/114.114.114.114 +server=/gsp4-cn.ls.apple.com/114.114.114.114 +server=/gsp5-cn.ls.apple.com/114.114.114.114 +server=/gspe19-cn.ls-apple.com.akadns.net/114.114.114.114 +server=/gspe19-cn.ls.apple.com/114.114.114.114 +server=/gspe21.ls.apple.com/114.114.114.114 +server=/gspe21-ssl.ls.apple.com/114.114.114.114 +server=/gspe35-ssl.ls.apple.com/114.114.114.114 +server=/icloud.cdn-apple.com/114.114.114.114 +server=/images.apple.com/114.114.114.114 +server=/itunes-apple.com.akadns.net/114.114.114.114 +server=/itunes.apple.com/114.114.114.114 +server=/itunesconnect.apple.com/114.114.114.114 +server=/mesu.apple.com/114.114.114.114 +server=/mesu-china.apple.com.akadns.net/114.114.114.114 +server=/phobos-apple.com.akadns.net/114.114.114.114 +server=/phobos.apple.com/114.114.114.114 +server=/store.apple.com/114.114.114.114 +server=/store.storeimages.cdn-apple.com/114.114.114.114 +server=/support.apple.com/114.114.114.114 +server=/swcdn.apple.com/114.114.114.114 +server=/swdist.apple.com/114.114.114.114 +server=/www.apple.com/114.114.114.114 diff --git a/etc/china.conf b/etc/china.conf deleted file mode 100644 index e886276..0000000 --- a/etc/china.conf +++ /dev/null @@ -1,5 +0,0 @@ -server=8.8.8.8#53 -server=127.0.0.1#5553 - -server=/baidu.com/114.114.114.114 -# refer https://github.com/felixonmars/dnsmasq-china-list diff --git a/etc/godns.conf b/etc/godns.conf index 50429f2..a94be7a 100644 --- a/etc/godns.conf +++ b/etc/godns.conf @@ -12,8 +12,9 @@ host = "127.0.0.1" port = 53 [resolv] -#Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq -server-list-file = "./etc/china.conf" +# Domain-specific nameservers configuration, formatting keep compatible with Dnsmasq +# Semicolon separate multiple files. +server-list-file = "./etc/apple.china.conf;./etc/google.china.conf" resolv-file = "/etc/resolv.conf" timeout = 5 # 5 seconds # The concurrency interval request upstream recursive server diff --git a/etc/google.china.conf b/etc/google.china.conf new file mode 100644 index 0000000..0928c70 --- /dev/null +++ b/etc/google.china.conf @@ -0,0 +1,42 @@ +server=/265.com/114.114.114.114 +server=/2mdn.net/114.114.114.114 +server=/app-measurement.com/114.114.114.114 +server=/beacons.gcp.gvt2.com/114.114.114.114 +server=/beacons.gvt2.com/114.114.114.114 +server=/beacons3.gvt2.com/114.114.114.114 +server=/c.admob.com/114.114.114.114 +server=/c.android.clients.google.com/114.114.114.114 +server=/cache.pack.google.com/114.114.114.114 +server=/clientservices.googleapis.com/114.114.114.114 +server=/connectivitycheck.gstatic.com/114.114.114.114 +server=/csi.gstatic.com/114.114.114.114 +server=/dl.google.com/114.114.114.114 +server=/doubleclick.net/114.114.114.114 +server=/e.admob.com/114.114.114.114 +server=/fonts.googleapis.com/114.114.114.114 +server=/fonts.gstatic.com/114.114.114.114 +server=/google-analytics.com/114.114.114.114 +server=/googleadservices.com/114.114.114.114 +server=/googleanalytics.com/114.114.114.114 +server=/googlesyndication.com/114.114.114.114 +server=/googletagmanager.com/114.114.114.114 +server=/googletagservices.com/114.114.114.114 +server=/imasdk.googleapis.com/114.114.114.114 +server=/kh.google.com/114.114.114.114 +server=/khm.google.com/114.114.114.114 +server=/khm.googleapis.com/114.114.114.114 +server=/khm0.google.com/114.114.114.114 +server=/khm0.googleapis.com/114.114.114.114 +server=/khm1.google.com/114.114.114.114 +server=/khm1.googleapis.com/114.114.114.114 +server=/khm2.google.com/114.114.114.114 +server=/khm2.googleapis.com/114.114.114.114 +server=/khm3.google.com/114.114.114.114 +server=/khm3.googleapis.com/114.114.114.114 +server=/khmdb.google.com/114.114.114.114 +server=/khmdb.googleapis.com/114.114.114.114 +server=/media.admob.com/114.114.114.114 +server=/mediavisor.doubleclick.com/114.114.114.114 +server=/redirector.gvt1.com/114.114.114.114 +server=/toolbarqueries.google.com/114.114.114.114 +server=/update.googleapis.com/114.114.114.114 diff --git a/etc/server_list.example.conf b/etc/server_list.example.conf new file mode 100644 index 0000000..c0847fe --- /dev/null +++ b/etc/server_list.example.conf @@ -0,0 +1,7 @@ +# Default upstream servers which have higher priority than the nameserver +# that configuration in `/etc/resolv.conf` +server=8.8.8.8#53 + +server=/google.com/8.8.8.8 +server=/baidu.com/114.114.114.114 +# refer https://github.com/felixonmars/dnsmasq-china-list diff --git a/resolver.go b/resolver.go index 689ab19..1afe8b8 100644 --- a/resolver.go +++ b/resolver.go @@ -62,11 +62,7 @@ func NewResolver(c ResolvSettings) *Resolver { return r } -func (r *Resolver) ReadServerListFile(file string) { - buf, err := os.Open(file) - if err != nil { - panic("Can't open " + file) - } +func (r *Resolver) parseServerListFile(buf *os.File) { scanner := bufio.NewScanner(buf) for scanner.Scan() { line := scanner.Text() @@ -88,6 +84,7 @@ func (r *Resolver) ReadServerListFile(file string) { case 3: domain := tokens[1] ip := tokens[2] + if !isDomain(domain) || !isIP(ip) { continue } @@ -116,6 +113,18 @@ func (r *Resolver) ReadServerListFile(file string) { } +func (r *Resolver) ReadServerListFile(path string) { + files := strings.Split(path, ";") + for _, file := range files { + buf, err := os.Open(file) + if err != nil { + panic("Can't open " + file) + } + defer buf.Close() + r.parseServerListFile(buf) + } +} + // Lookup will ask each nameserver in top-to-bottom fashion, starting a new request // in every second, and return as early as possbile (have an answer). // It returns an error if no request has succeeded.