Giter Club home page Giter Club logo

geodns's Introduction

GeoDNS servers

This is the DNS server powering the NTP Pool system and other similar services.

OpenSSF Best Practices

Questions or suggestions?

For bug reports or feature requests, please create an issue. For questions or discussion, you can post to the GeoDNS category on the NTP Pool forum.

Installation

Release builds are available in a yum repository at https://pkgs.ntppool.org/yum/ and apt (debian, ubuntu) packages at https://pkgs.ntppool.org/apt/.

From source

If you don't have Go installed the easiest way to build geodns from source is to download and install Go from https://golang.org/dl/.

GeoDNS generally requires a recent version of Go (one of the last few major versions)

git clone https://github.com/abh/geodns.git
cd geodns
go build
./geodns -h

You can also build with goreleaser.

Sample configuration

There's a sample configuration file in dns/example.com.json. This is currently derived from the test.example.com data used for unit tests and not an example of a "best practices" configuration.

For testing there's also a bigger test file at:

mkdir -p dns
curl -o dns/test.ntppool.org.json http://tmp.askask.com/2012/08/dns/ntppool.org.json.big

Run it

After building the server you can run it with:

./geodns -log -interface 127.1 -port 5053

To test the responses run

dig -t a test.example.com @127.1 -p 5053

or

dig -t ptr 2.1.168.192.IN-ADDR.ARPA. @127.1 -p 5053

or more simply put

dig -x 192.168.1.2 @127.1 -p 5053

The binary can be moved to /usr/local/bin, /opt/geodns/ or wherever you find appropriate.

Configuration

See the sample configuration file.

Notable command line parameters (and their defaults)

  • -config="./dns/"

Directory of zone files (and configuration named geodns.conf).

  • -checkconfig=false

Check configuration file, parse zone files and exit

  • -interface="*"

Comma separated IPs to listen on for DNS requests.

  • -port="53"

Port number for DNS requests (UDP and TCP)

  • -http=":8053"

Listen address for HTTP interface. Specify as 127.0.0.1:8053 to only listen on localhost.

  • -identifier=""

Identifier for this instance (hostname, pop name or similar).

It can also be a comma separated list of identifiers where the first is the "server id" and subsequent ones are "group names", for example region of the server, name of anycast cluster the server is part of, etc. This is used in (future) reporting/statistics features.

  • -log=false

Enable to get lots of extra logging, only useful for testing and debugging. Absolutely not recommended in production unless you get very few queries (less than 1-200/second).

  • -cpus=4

Maximum number of CPUs to use. Set to 0 to match the number of CPUs available on the system (also the default).

Logging

GeoDNS supports query logging to JSON or Avro files (see the sample configuration file for options).

Prometheus metrics

/metrics on the http port provides a number of metrics in Prometheus format.

Runtime status page, Websocket metrics & StatHat integration

The runtime status page, websocket feature and StatHat integration have been replaced with Prometheus metrics.

Country and continent lookups

See zone targeting options below.

Weighted records

Most records can have a 'weight' assigned. If any records of a particular type for a particular name have a weight, the system will return max_hosts records (default 2).

If the weight for all records is 0, all matching records will be returned. The weight for a label can be any integer as long as the weights for a label and record type is less than 2 billion.

As an example, if you configure

10.0.0.1, weight 10
10.0.0.2, weight 20
10.0.0.3, weight 30
10.0.0.4, weight 40

with max_hosts 2 then .4 will be returned about 4 times more often than .1.

Configuration file

The geodns.conf file allows you to specify a specific directory for the GeoIP data files and other options. See the geodns.conf.sample file for example configuration.

The global configuration file is not reloaded at runtime.

Most of the configuration is "per zone" and done in the zone .json files. The zone configuration files are automatically reloaded when they change.

Zone format

In the zone configuration file the whole zone is a big hash (associative array). At the top level you can (optionally) set some options with the keys serial, ttl and max_hosts.

The actual zone data (dns records) is in a hash under the key "data". The keys in the hash are hostnames and the value for each hostname is yet another hash where the keys are record types (lowercase) and the values an array of records.

For example to setup an MX record at the zone apex and then have a different A record for users in Europe than anywhere else, use:

{
    "serial": 1,
    "data": {
        "": {
            "ns": [ "ns.example.net", "ns2.example.net" ],
            "txt": "Example zone",
            "spf": [ { "spf": "v=spf1 ~all", "weight": 1 } ],
            "mx": { "mx": "mail.example.com", "preference": 10 }
        },
        "mail": { "a": [ ["192.168.0.1", 100], ["192.168.10.1", 50] ] },
        "mail.europe": { "a": [ ["192.168.255.1", 0] ] },
        "smtp": { "alias": "mail" }
    }
}

The configuration files are automatically reloaded when they're updated. If a file can't be read (invalid JSON, for example) the previous configuration for that zone will be kept.

Zone options

  • serial

GeoDNS doesn't support zone transfers (AXFR), so the serial number is only used for debugging and monitoring. The default is the 'last modified' timestamp of the zone file.

  • ttl

Set the default TTL for the zone (default 120).

  • targeting

  • max_hosts

  • contact

Set the soa 'contact' field (default is "hostmaster.$domain").

Zone targeting options

@

country continent

region and regiongroup

Supported record types

Each label has a hash (object/associative array) of record data, the keys are the type. The supported types and their options are listed below.

Adding support for more record types is relatively straight forward, please open a ticket in the issue tracker with what you are missing.

A

Each record has the format of a short array with the first element being the IP address and the second the weight.

[ [ "192.168.0.1", 10], ["192.168.2.1", 5] ]

See above for how the weights work.

AAAA

Same format as A records (except the record type is "aaaa").

Alias

Internally resolved cname, of sorts. Only works internally in a zone.

"foo"

CNAME

"target.example.com."
"www"

The target will have the current zone name appended if it's not a FQDN (since v2.2.0).

MX

MX records support a weight similar to A records to indicate how often the particular record should be returned.

The preference is the MX record preference returned to the client.

{ "mx": "foo.example.com" }
{ "mx": "foo.example.com", "weight": 100 }
{ "mx": "foo.example.com", "weight": 100, "preference": 10 }

weight and preference are optional.

NS

NS records for the label, use it on the top level empty label ("") to specify the nameservers for the domain.

[ "ns1.example.com", "ns2.example.com" ]

There's an alternate legacy syntax that has space for glue records (IPv4 addresses), but in GeoDNS the values in the object are ignored so the list syntax above is recommended.

{ "ns1.example.net.": null, "ns2.example.net.": null }

TXT

Simple syntax

"Some text"

Or with weights

{ "txt": "Some text", "weight": 10 }

SPF

An SPF record is semantically identical to a TXT record with the exception that the label is set to 'spf'. An example of an spf record with weights:

{ "spf": "v=spf1 ~all]", "weight": 1 }

An spf record is typically at the root of a zone, and a label can have an array of SPF records, e.g

  "spf": [ { "spf": "v=spf1 ~all", "weight": 1 } , "spf": "v=spf1 10.0.0.1", "weight": 100]

SRV

An SRV record has four components: the weight, priority, port and target. The keys for these are "srv_weight", "priority", "target" and "port". Note the difference between srv_weight (the weight key for the SRV qtype) and "weight".

An example srv record definition for the _sip._tcp service:

"_sip._tcp": {
    "srv": [ { "port": 5060, "srv_weight": 100, "priority": 10, "target": "sipserver.example.com."} ]
},

Much like MX records, SRV records can have multiple targets, eg:

"_http._tcp": {
    "srv": [
        { "port": 80, "srv_weight": 10, "priority": 10, "target": "www.example.com."},
        { "port": 8080, "srv_weight": 10, "priority": 20, "target": "www2.example.com."}
    ]
},

License and Copyright

This software is Copyright 2012-2015 Ask Bjørn Hansen. For licensing information please see the file called LICENSE.

geodns's People

Contributors

abh avatar abligh avatar coocood avatar faide avatar gpapilion avatar kisielk avatar leifj avatar miekg avatar miouge1 avatar snebel29 avatar tydavis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geodns's Issues

TTL cannot be set per record

TTLs for records are being ignored; GeoDNS does only take into account the zone's default TTL.

For example, given test.example.com, lines 32–35 with the default TTL of 600 and a configured TTL of 601 for bar.test.example.com,
I expect this:

$ ./geodns --port=3053 &

$ dig @127.0.0.1 -p 3053 a bar.test.example.com | grep -A 1 -F "ANSWER SECTION" | cut -f 2 -d ' '
ANSWER
601

$ dig @127.0.0.1 -p 3053 cname cname-long-ttl.test.example.com | grep -A 1 -F "ANSWER SECTION" | cut -f 2 -d ' '
ANSWER
86400

$ kill %1

But the result is the default TTL:

ANSWER
600

ANSWER
600

Add windows/windows64 build support guide.

How can i build on windows without having problem on cygwin? Here's my error log(translated from italian):
Luckcolors@Luckcolors-PC ~
$ go get github.com/abh/geodns
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status

Closes UDP socket randomly(?)

This is a followup to miekg/dns#21 (which really was about something else).

I ran dnsbench against the geodns server today to reproduce the "hang" where it just stops listening on UDP. After 4 hours of 1000qps it was still working fine and it's "only" doubled memory usage from 15MB to 30MB.

Running lsof on the process shows it's doesn't have the UDP server open anymore.

I've added some monitoring code in 70b6e4e and an attempt at logging if ListenAndServe returns: 98020a3

DNSSEC support?

Hello,

Do you want to support DNSSEC?

There are two issues at stack here:

  1. DNSSEC is dependent on a correct clock, hence everybody uses NTP. But this creates a catch-22 when DNSSEC validation errors break NTP.

  2. Go DNS (and fksd) does not make DNSSEC as easy as it should, but this is minor compared to 1)

picker makes garbage

From doing some memory profiling it looks like picker.go makes a fair amount of garbage when it copies the list of records so it can manipulate it to not get duplicate results.

(cc @miekg for suggestions).

Metrics spam in console

I keep getting spam like this in console (no queries are happening at all). It just keeps spamming so fast it is impossible to even read anything. Is there any way I could disable those messages?

metrics: 10:24:10.402793   count:               0
metrics: 10:24:10.402801   1-min rate:          0.00
metrics: 10:24:10.402805   5-min rate:          0.00
metrics: 10:24:10.402808   15-min rate:         0.00
metrics: 10:24:10.402819   mean rate:           0.00
metrics: 10:24:10.402830 histogram queries-histogram
metrics: 10:24:10.402834   count:               2
metrics: 10:24:10.402838   min:                 0
metrics: 10:24:10.402842   max:                 0
metrics: 10:24:10.402847   mean:                0.00
metrics: 10:24:10.402851   stddev:              0.00
metrics: 10:24:10.402856   median:              0.00
metrics: 10:24:10.402860   75%:                 0.00
metrics: 10:24:10.402864   95%:                 0.00
metrics: 10:24:10.402869   99%:                 0.00
metrics: 10:24:10.402873   99.9%:               0.00
metrics: 10:24:10.402878 gauge goroutines
metrics: 10:24:10.402882   value:              35
metrics: 10:24:10.402886 meter pgeodns queries
metrics: 10:24:10.402890   count:               0
metrics: 10:24:10.402894   1-min rate:          0.00
metrics: 10:24:10.402913   5-min rate:          0.00
metrics: 10:24:10.402919   15-min rate:         0.00
metrics: 10:24:10.402923   mean rate:           0.00
metrics: 10:24:10.402928 meter pgeodns EDNS queries
metrics: 10:24:10.402932   count:               0
metrics: 10:24:10.402936   1-min rate:          0.00
metrics: 10:24:10.402941   5-min rate:          0.00
metrics: 10:24:10.402945   15-min rate:         0.00
metrics: 10:24:10.402950   mean rate:           0.00
metrics: 10:24:10.402954 meter foxelbox.com queries
metrics: 10:24:10.402958   count:               0
metrics: 10:24:10.402963   1-min rate:          0.00
metrics: 10:24:10.402967   5-min rate:          0.00
metrics: 10:24:10.402971   15-min rate:         0.00
metrics: 10:24:10.402982   mean rate:           0.00
metrics: 10:24:10.402986 meter foxelbox.com EDNS queries
metrics: 10:24:10.402990   count:               0
metrics: 10:24:10.402994   1-min rate:          0.00
metrics: 10:24:10.402999   5-min rate:          0.00
metrics: 10:24:10.403003   15-min rate:         0.00
metrics: 10:24:10.403007   mean rate:           0.00

Go version is "go version go1.3 linux/amd64", I installed geodns with "go get github.com/abh/geodns"

multiple config directory

Is there any option to mention multiple configuration directory. ?. As I can add only one config directory using --config option. Sub directory json files are not loading. Else, Configuration has any include options like pgeodns. ? .

Reason behind is, Easy to isolate the Customer zone files. Mean, I create a directory for each customers and put their zone files there. So its so easy to manage the configurations.

Add HTTP server

Add basic http server to show statistics and other runtime information.

findLabel and the selector

The selector in findLabel generates garbage. It would be beter to completely remove this from this (often called) function.

status as json

I'm trying to build a munin-plugin (StatHat isn't for me) and it would be good to have a json-formatted status page so one doesn't have to parse html to get at the counters.

I guess the "clean" way to do this would be to use the Accept-header but that might be overdoing it.

Thoughts?

I might take a whack at it unless somebody already has/wants to.

clarification on how to set different answer per geo

I've got geodns up and running with a sample zone file. What's not clear is how I set different answers for different Geos. Do I just add the geo after the record name. As an example:

"www" : { "a" : "192.168.0.1" },
"www.us" : { "a" : "192.168.1.1" },
"www.ca" : " { "a" : "192.168.2.1"},
"www.europe" : {"a" : 192.168.3.1" }

And is there a way to have different answers for different US states?

thanks in advance

Not Websocket protocol

When I hit this url in browser, getting "Not Websokcet Protocol" [ http://172.20.1.10:8053/monitor]. But this page is working [ http://172.20.1.10:8053/status].

Please help me on this.

Automatically reload json zone configuration

Have a goroutine check if the json files have been updated every 5-10 seconds. When a file has been updated, reload it atomically and safely (if loading the new file fails, continue running with the old file).

Geo ip | Perl | windows

Hi,

I am facing issue while running the perl script in windows

Error opening C:PerlibGeoIPGeoIP.dat at (eval 5) line 4923, line 705.

Please help me to resolve this issues.

match-clients equivalent (or mapping blocks/ip to countries)

For developing countries, MaxMind database is unreliable but we can find resolver IP addresses/blocks from relevant ISPs and thus have accurate data thanks to the resolver.

It would be perfect if geodns allowed to manually map addresses/blocks to specific countries, taking priority over what MaxMind returns, more or less what we would do in bind with match-clients.

cname support problems

When matching with a cname, it doesn't appear like we do the country lookup logic when the question

License?

Just wondering what license the Go version of geodns is released under. Apache like pgeodns?

can't open geoip database

Error Opening file /usr/share/local/GeoIP/GeoIP.dat
Error Opening file /opt/local/share/GeoIP/GeoIP.dat
2012/08/30 10:05:02 Error opening GeoIP database [/usr/share/GeoIP/GeoIP.dat /usr/share/local/GeoIP/GeoIP.dat /opt/local/share/GeoIP/GeoIP.dat] no such file or directory
2012/08/30 10:05:02 Could not open GeoIP database
geodns 10:05:02.010356 geodns.go:28: Starting geodns/2.0
geodns 10:05:02.010381 config.go:320: SOA: pgeodns. 3600 IN SOA ns support.bitnames.com. 0 5400 5400 2419200 0

While the file is there:
% ls -l /usr/share/GeoIP/GeoIP.dat
-rw-r--r-- 1 root root 1.6M Jan 3 2012 /usr/share/GeoIP/GeoIP.dat

Zone List?

Is there a list of where county/continent zone names exist like for 'JP' and 'Europe'?

If not can we create one on the wiki.

Thanks :)

Add 'identification' option

Add an option to specify a text to use as the identification instead of the first IP address the server is listening to.

HEAD doesn't build with abh/go-metrics

./metrics.go:26: cannot use metrics.NewHistogram(metrics.NewUniformSample(1800)) (type metrics.Histogram) as type *metrics.StandardHistogram in assignment: need type assertion
./metrics.go:29: cannot use metrics.NewHistogram(metrics.NewExpDecaySample(600, 0.015)) (type metrics.Histogram) as type *metrics.StandardHistogram in assignment: need type assertion
./metrics.go:32: cannot use metrics.NewGauge() (type metrics.Gauge) as type *metrics.StandardGauge in assignment: need type assertion
./zone.go:85: cannot use metrics.NewMeter() (type metrics.Meter) as type *metrics.StandardMeter in assignment: need type assertion

use log.Printf* instead of fmt.Printf*

Pro-tip: start using log. The sooner the better and you can leave all those log.Printf* in there. I think hooking up syslog is possible, but I haven't done that (yet)

Support for SRV records

Support SRV records; figure out if something smart should be done with the extra weight/priority attributes those records have.

(this is a followup ticket to issue #20)

If records have weight, choose randomly based on weight

If records have weight configured, choose them randomly based on the weight. The perl implementation sorts the records by weight (descending), adds up the total weight and then generates a random number between 0 and then loops through the records until the accumulated weight is higher than the random number.

Stackoverflow suggests basically the same algorithm, though modifying the slice after each pick to avoid duplicates (the perl version tries doing that with brute-force).

Can you do some support to make it work on ubuntu?

I tried install geodns on ubuntu a number of times, but failed. It seems there are some problems in terms of packages dependencies. Besides, I also got the error message:

/usr/lib/go/src/pkg/github.com/abh/dns/edns.go:230: function ends without a return statement

without a clue

The steps I tried:
sudo apt-get install golang
sudo apt-get install mercurial
sudo apt-get install libgeoip-dev
export GOPATH=/usr/lib/go
sudo go get github.com/abh/geodns

I haven't tried to install it on centos, so I cannot tell if I tried to install it in wrong way.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.