Skip to content

Commit

Permalink
Add support for multi dynamic servers (#5)
Browse files Browse the repository at this point in the history
* Fix Build badge

* Can now pass multiple dynamic nameservers

* Simplify entry point script

* Finalize entry point script

* Update README

* Fix typo

* Add default dnsmasq config file
  • Loading branch information
tschaffter authored Mar 25, 2021
1 parent d228529 commit 2101467
Show file tree
Hide file tree
Showing 4 changed files with 750 additions and 40 deletions.
63 changes: 38 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
# Dnsmasq

[![GitHub Release](https://img.shields.io/github/release/tschaffter/dnsmasq.svg?include_prereleases&color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/releases)
[![GitHub CI](https://img.shields.io/github/workflow/status/tschaffter/dnsmasq/ci.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/actions)
[![GitHub CI](https://img.shields.io/github/workflow/status/tschaffter/dnsmasq/CI.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/actions)
[![GitHub License](https://img.shields.io/github/license/tschaffter/dnsmasq.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/blob/develop/LICENSE)
[![Docker Pulls](https://img.shields.io/docker/pulls/tschaffter/dnsmasq.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/r/tschaffter/dnsmasq)

Docker image for Dnsmasq

## Overview

[Dnsmasq] (short for DNS masquerade) is a lightweight, easy to configure DNS
forwarder, designed to provide DNS (and optionally DHCP and TFTP) services to a
small-scale network. It can serve the names of local machines which are not in
the global DNS.
[Dnsmasq] is a lightweight, easy to configure DNS forwarder, designed to provide
DNS (and optionally DHCP and TFTP) services to a small-scale network. It can
also serve the names of local machines which are not in the global DNS.If you
own an Asus router, there is a chance that [your Asus router is using Dnsmasq].

## Features

- Brings the latest release of Dnsmasq to Rapsberry Pi OS and other Debian
derivatives.
- Enables Dnsmasq to resolve the hostname of an upstream server running in a
Docker container.
- Brings the latest release of Dnsmasq (2.84) to Rapsberry Pi OS and other
Debian derivatives.
- Enables Dnsmasq to resolve the hostname of an upstream nameserver running in a
Docker container (e.g. Stubby).
- Provides a Docker image that I can trust until an official image is available
for Dnsmasq.

## Usage

### Set upstream nameserver
### Configuration

There are two ways to specify the address of an upstream nameserver:
There are three sources of configuration that you can use:

- By specifying `server=` in one of Dnsmasq configuration files
- [dnsmasq.conf](dnsmasq.conf) or
- [dnsmasq.d/example.com.conf](dnsmasq.d/example.com.conf)
- By specifying the environment variables `SERVER_HOST` and `SERVER_PORT` in
*docker-compose.yml*.
- Main configuration: [dnsmasq.conf](dnsmasq.conf)
- Domain-specific configuration(s): [dnsmasq.d/example.com.conf](dnsmasq.d/example.com.conf)
- Command-line arguments

Both ways can be used to specify a public nameserver like Google Public DNS
(`8.8.8.8`):
The file [dnsmasq.conf.example](dnsmasq.conf.example) is the default main
configuration file provided with the latest release of Dnsmasq available in this
GitHub repository. The file [dnsmasq.conf](dnsmasq.conf) highlights some options
of Dnsmasq.

- `server=8.8.8.8` or
- `SERVER_HOST=8.8.8.8` and `SERVER_PORT=53`
### Set upstream nameservers

The second method can be used to specify the service name of a dockerized DNS
server. For example, one could use [Stubby] as a local DNS Privacy stub resolver
that can be used in addition to Dnsmasq to enable DNS-over-TLS.
Static nameservers like Cloudflare DNS servers `1.1.1.1` and `1.0.0.1` or Google
DNS servers `8.8.8.8` and `8.8.4.4` can be specified using any sources of
configuration.

One of the reason for building this Docker image is because Dnsmasq cannot
resolve the address from a nameserver that is not an IP address. This is a
problem when using a nameserver like [Stubby] in a Docker container whose
address is commonly referenced by its Docker service name. Stubby is a local DNS
Privacy stub resolver that can be used in addition to Dnsmasq to enable
DNS-over-TLS.

A solution to the problem mentioned above is implemented in the entrypoint
script [docker-entrypoint.sh](docker-entrypoint.sh) where the address specified
for a nameserver is resolved to an IP address using the command `ping`. Thus,
this solution only applies to server addresses specified as command-line
arguments.

### Deploying using Docker

Expand Down Expand Up @@ -98,7 +110,7 @@ See example specified in
[dnsmasq.d/example.com.conf](dnsmasq.d/example.com.conf).

```console
$ dig @localhost +noall +answer +stats host1.example.com
$ dig @localhost +noall +answer +stats myhost.example.com
myhost.example.com. 0 IN A 192.168.1.10
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
Expand All @@ -122,9 +134,10 @@ installed.
<!-- Links -->

[Dnsmasq]: https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=summary
[your Asus router is using Dnsmasq]: https://unfinishedbitness.info/2015/05/26/asuswrt-finalized-setup/
[Stubby]: https://github.com/getdnsapi/stubby
[Dig]: https://en.wikipedia.org/wiki/Dig_(command)

[Stubby server]: https://github.com/tschaffter/stubby
[How to Do DNS Caching with dnsmasq]: https://netbeez.net/blog/linux-dns-caching-dnsmasq/
[Apache License 2.0]: https://github.com/nlpsandbox/date-annotator-example/blob/main/LICENSE
[Apache License 2.0]: https://github.com/nlpsandbox/date-annotator-example/blob/main/LICENSE
Loading

0 comments on commit 2101467

Please sign in to comment.