Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/louisbrunner/avahi2dns
Small DNS server which interface with avahi (perfect for Alpine Linux and musl)
https://github.com/louisbrunner/avahi2dns
alpine avahi dns docker mdns multicast-dns musl
Last synced: 4 days ago
JSON representation
Small DNS server which interface with avahi (perfect for Alpine Linux and musl)
- Host: GitHub
- URL: https://github.com/louisbrunner/avahi2dns
- Owner: LouisBrunner
- License: mit
- Created: 2021-09-07T18:10:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-02T21:51:23.000Z (11 months ago)
- Last Synced: 2024-06-20T12:18:25.496Z (5 months ago)
- Topics: alpine, avahi, dns, docker, mdns, multicast-dns, musl
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 15
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# avahi2dns [![Build](https://github.com/LouisBrunner/avahi2dns/actions/workflows/build.yml/badge.svg)](https://github.com/LouisBrunner/avahi2dns/actions/workflows/build.yml)
Small DNS server which interface with avahi (perfect for Alpine Linux and musl)
## Building
Requires go 1.16 or later
```
go build
```## Usage
```shell
$ ./avahi2dns -h
Usage: avahi2dns [--domains DOMAINS] [--addr ADDR] [--port PORT] [--debug]Options:
--domains DOMAINS, -d DOMAINS
comma-separated list of domains to resolve
--addr ADDR, -a ADDR address to bind on [default: localhost]
--port PORT, -p PORT port to bind on [default: 53]
--debug, -v also include debug information [default: false]
--help, -h display this help and exit
```### Examples
By default the server will bind to port 53 on localhost (not accessible outside the computer) and resolve any domain with the following extensions: `home`, `internal`, `intranet`, `lan`, `local`, `private`, `test`
```shell
$ sudo ./avahi2dns
INFO[0000] starting DNS server addr="localhost:53"
...
```Settings can be changed through command-line arguments or environment variables:
```shell
$ ./avahi2dns -p 5454 -a '0.0.0.0' -d 'local,home'
or
$ BIND='0.0.0.0' PORT=5454 ./avahi2dns -d 'local,home'
```You can also use the debug flag if you need more information about what the server is doing (probably overkill):
```shell
$ ./avahi2dns -v -p 5454
DEBU[0000]avahi2dns/server.go:14 main.runServer() connection to dbus...
DEBU[0000]avahi2dns/server.go:21 main.runServer() connection to avahi through dbus...
DEBU[0000]avahi2dns/server.go:37 main.runServer() adding dns handler domain=home
...
```## Using with Alpine and Docker on Linux
Linux DNS-resolution is done by the standard library (through functions like `getaddrinfo` or `gethostbyname`), unfortunately `musl` used by Alpine Linux doesn't support mdns out-of-the-box.
However you can easily add this lookup through `avahi2dns`:```shell
$ sudo ./avahi2dns &
INFO[0000] starting DNS server addr="localhost:53"
$ docker run --rm --entrypoint ash --net=host alpine -c 'apk add iputils && echo "nameserver 127.0.0.1" >> /etc/resolv.conf && ping your-name-host.local'
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/armv7/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/armv7/APKINDEX.tar.gz
(1/2) Installing libcap (2.50-r0)
(2/2) Installing iputils (20210202-r0)
Executing busybox-1.33.1-r3.trigger
OK: 4 MiB in 16 packages
INFO[0006] forwarding query to avahi component=main name=your-name-host.local. protocol=0 type=A
INFO[0006] forwarding query to avahi component=main name=your-name-host.local. protocol=1 type=AAAA
PING your-name-host.local (172.16.16.2) 56(84) bytes of data.
64 bytes from 172.16.16.2 (172.16.16.2): icmp_seq=1 ttl=64 time=0.456 ms
64 bytes from 172.16.16.2 (172.16.16.2): icmp_seq=2 ttl=64 time=0.426 ms
64 bytes from 172.16.16.2 (172.16.16.2): icmp_seq=3 ttl=64 time=0.429 ms
64 bytes from 172.16.16.2 (172.16.16.2): icmp_seq=4 ttl=64 time=0.418 ms
```Note: this requires your Docker container to use `--net=host` instead of the default `--net=bridge`, but that it might be possible without using the latest Docker distributions
Note: `avahi2dns` is run as a background job for the sake of demonstration, you should really run it through `systemd` or similar