项目作者: cirocosta

项目描述 :
Minimal A and NS record resolver
高级语言: Go
项目地址: git://github.com/cirocosta/sdns.git
创建时间: 2017-08-14T02:21:28Z
项目社区:https://github.com/cirocosta/sdns

开源协议:

下载


sdns 📂

A DNS server based on minimal static configuration


Build Status

Use cases

Make a domain always resolve to localhost

  1. sudo sdns \
  2. --port 53 \
  3. --addr 127.0.0.11 \
  4. 'domain=test.cirocosta.io,ip=192.168.0.103,ns=mynameserver.com' \
  5. 'domain=*.cirocosta.io,ip=127.0.0.1,ip=10.0.0.10'

Retrieve information about each DNS request being performed

  1. sudo sdns \
  2. --debug \ # logs the requests to 'stderr'
  3. --port 53 \
  4. --addr 127.0.0.11 \
  5. --recursor 8.8.8.8

Install

Pick the latest version in the project’s releases page and then “untar” the binary to the desired location in $PATH.

For instance:

  1. URL=https://github.com/cirocosta/sdns/releases/download/v0.0.1/sdns_0.0.1_darwin_amd64.tar.gz
  2. mkdir -p /tmp/sdns
  3. curl -o /tmp/sdns/sdns.tar.gz -L $URL
  4. tar xzfv /tmp/sdns/sdns.tar.gz -C /tmp/sdns
  5. sudo mv /tmp/sdns/sdns /usr/local/bin/sdns

Note.: you can also use go to install it: go get -u github.com/cirocosta/sdns. Just make sure that you can run the binary with the necessary privileges to bind to port 53.

Docker

Using sdns in a Docker container is completely fine, you can find the image under cirocosta/sdns.

  1. docker run -d \
  2. --network host \ # use the host network stack (not required)
  3. cirocosta/sdns \ # use the image
  4. --debug \ # logs the requests to 'stderr'
  5. --port 53 \
  6. --addr 127.0.0.11 \
  7. --recursor 8.8.8.8

Usage

  1. Usage: sdns [--port PORT] [--address ADDRESS] [--debug] [--recursor RECURSOR] [DOMAINS [DOMAINS ...]]
  2. Positional arguments:
  3. DOMAINS list of domains
  4. Options:
  5. --port PORT, -p PORT port to listen to [default: 1053]
  6. --address ADDRESS, -a ADDRESS
  7. address to bind to
  8. --debug, -d turn debug mode on [default: true]
  9. --recursor RECURSOR, -r RECURSOR
  10. list of recursors to honor [default: [8.8.8.8 8.8.4.4]]
  11. --help, -h display this help and exit

Running as the system’s DNS

Ubuntu 17.04

If you’re on Ubuntu 17.04 you might have noticed that systemd places a DNS resolver at 127.0.0.53:

  1. cat /etc/resolv.conf
  2. # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
  3. # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
  4. # 127.0.0.53 is the systemd-resolved stub resolver.
  5. # run "systemd-resolve --status" to see details about the actual nameservers.
  6. 127.0.0.53

As systemd-resolve is a systemd service like any other, we just need to stop the unit and then place sdns at 127.0.0.53 listening on the default DNS service port (53):

  1. sudo systemctl stop systemd-resolved
  2. sudo sdns \ # run as sudo to be able to bind to 53
  3. --debug \ # with --debug we capture more logs
  4. --address 127.0.0.53 \ # listen on the expected IP
  5. --port 53 # on port 53
  6. # Now if you stop 'sdns' you'll lose DNS resolving.
  7. # To get systemd-resolve in place again just
  8. # issue `sudo systemctl start systemd-resolved`.

Now you can head to your web browser and see the queries coming to SDNS.

If you wish you can also run sdns as a systemd service (like systemd-resolved)