Home

Awesome

go-dnsmasq

Latest Version Github All Releases Docker Pulls License

go-dnsmasq is a lightweight (1.2 MB) DNS caching server/forwarder with minimal filesystem and runtime overhead.

Application examples:

Features

Resolve logic

DNS queries are resolved in the style of the GNU libc resolver:

Command-line options / environment variables

FlagDescriptionDefaultEnvironment vars
--listen, -lAddress to listen on host[:port]127.0.0.1:53$DNSMASQ_LISTEN
--default-resolver, -dUpdate resolv.conf to make go-dnsmasq the host's nameserverFalse$DNSMASQ_DEFAULT
--nameservers, -nComma delimited list of nameservers host[:port]. IPv6 literal address must be enclosed in brackets. (supersedes etc/resolv.conf)-$DNSMASQ_SERVERS
--stubzones, -zUse different nameservers for given domains. Can be passed multiple times. domain[,domain]/host[:port][,host[:port]]-$DNSMASQ_STUB
--hostsfile, -fPath to a hosts file (e.g. ‘/etc/hosts‘)-$DNSMASQ_HOSTSFILE
--hostsfile-poll, -pHow frequently to poll hosts file for changes (seconds, ‘0‘ to disable)0$DNSMASQ_POLL
--search-domains, -sComma delimited list of search domains domain[,domain] (supersedes /etc/resolv.conf)-$DNSMASQ_SEARCH_DOMAINS
--enable-search, -searchQualify names with search domains to resolve queriesFalse$DNSMASQ_ENABLE_SEARCH
--rcache, -rCapacity of the response cache (‘0‘ disables caching)0$DNSMASQ_RCACHE
--rcache-ttlTTL for entries in the response cache60$DNSMASQ_RCACHE_TTL
--no-recDisable forwarding of queries to upstream nameserversFalse$DNSMASQ_NOREC
--fwd-ndotsNumber of dots a name must have before the query is forwarded0$DNSMASQ_FWD_NDOTS
--ndotsNumber of dots a name must have before making an initial absolute query (supersedes /etc/resolv.conf)1$DNSMASQ_NDOTS
--round-robinEnable round robin of A/AAAA recordsFalse$DNSMASQ_RR
--systemdBind to socket(s) activated by Systemd (ignores --listen)False$DNSMASQ_SYSTEMD
--verboseEnable verbose loggingFalse$DNSMASQ_VERBOSE
--syslogEnable syslog loggingFalse$DNSMASQ_SYSLOG
--multithreadingEnable multithreading (experimental)False
--help, -hShow help
--version, -vPrint the version

Enable Graphite/StatHat metrics

EnvVar: GRAPHITE_SERVER
Default:
Set to the host:port of the Graphite server

EnvVar: GRAPHITE_PREFIX
Default: go-dnsmasq
Set a custom prefix for Graphite metrics

EnvVar: STATHAT_USER
Default:
Set to your StatHat account email address

Usage

Run from the command line

Download the binary for your OS from the releases page.

go-dnsmasq is available in two versions. The minimal version (go-dnsmasq-min) has a lower memory footprint but doesn't have caching, stats reporting and systemd support.

   sudo ./go-dnsmasq [options]

Run as a Docker container

Docker Hub trusted builds are available.

docker run -d -p 53:53/udp -p 53:53 janeczku/go-dnsmasq:latest

You can pass go-dnsmasq configuration parameters by setting the corresponding environmental variables with Docker's -e flag.

Serving A/AAAA records from a hosts file

The --hostsfile parameter expects a standard plain text hosts file with the only difference being that a wildcard * in the left-most label of hostnames is allowed. Wildcard entries will match any subdomain that is not explicitly defined. For example, given a hosts file with the following content:

192.168.0.1 db1.db.local
192.168.0.2 *.db.local

Queries for db2.db.local would be answered with an A record pointing to 192.168.0.2, while queries for db1.db.local would yield an A record pointing to 192.168.0.1.