Code Monkey home page Code Monkey logo

avahi2dns's Introduction

avahi2dns Build

Small DNS server which interface with avahi (perfect for Alpine Linux and musl)

Building

Requires go 1.16 or later

go build

Usage

$ ./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

$ sudo ./avahi2dns
INFO[0000] starting DNS server                           addr="localhost:53"
...

Settings can be changed through command-line arguments or environment variables:

$ ./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):

$ ./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:

$ 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

avahi2dns's People

Contributors

espindola avatar louisbrunner avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

espindola pg83

avahi2dns's Issues

ipv6 error

Hello!

Thank you for your program, it served perfectly what I needed.

I'm using both IPv4 and IPv6 and I got an error resolving names to IPv6. I didn't quite understand how the call to Avahi should be, however, changing from avahi.ProtoUnspec to the chosen protocol worked correctly.

hn, err := aserver.ResolveHostName(avahi.InterfaceUnspec, proto, name, avahi.ProtoUnspec, 0)

name does not resolve, but receives reqest and forwards to avahi

Hi,

I have an embedded target (musl) that I need to mdns resolution. I built avahi2mdns and deployed it successfully. I added a nameserver 127.0.0.1 entry to resolve.conf but when I attempt to ping a .local address from the embedded target ping fails. Interestingly, avahi2dns seems to do its job correctly however. Any idea what could be causing this? Log below.

Thanks!

avahi2dns -v
DEBU[0000]github.com/LouisBrunner/avahi2dns/config.go:32 main.parseArgs() config parsed config="&{[home internal intr
anet lan local private test] localhost 53 true}"
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:14 main.runServer() connection to dbus...
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:21 main.runServer() connection to avahi through dbus...
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=home
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=internal
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=intranet
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=lan
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=local
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=private
DEBU[0000]github.com/LouisBrunner/avahi2dns/server.go:37 main.runServer() adding dns handler domain=test
INFO[0000]github.com/LouisBrunner/avahi2dns/server.go:46 main.runServer() starting DNS server addr="localhost:53"
DEBU[0002]github.com/LouisBrunner/avahi2dns/server.go:30 main.runServer.func1() received request component=main request=";; opcode: QUERY, status: NOERROR, id: 5070\n;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0\n\n;; QUESTION SECTION:\n;hostname.local.\tIN\t A\n"
INFO[0002]github.com/LouisBrunner/avahi2dns/query.go:52 main.avahiToRecord() forwarding query to avahi component=main name=hostname.local. protocol=0 type=A
DEBU[0002]github.com/LouisBrunner/avahi2dns/server.go:30 main.runServer.func1() received request component=main request=";; opcode: QUERY, status: NOERROR, id: 10670\n;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0\n\n;; QUESTION SECTION:\n;hostname.local.\tIN\t AAAA\n"
INFO[0002]github.com/LouisBrunner/avahi2dns/query.go:52 main.avahiToRecord() forwarding query to avahi component=main name=hostname.local. protocol=1 type=AAAA
DEBU[0002]github.com/LouisBrunner/avahi2dns/server.go:32 main.runServer.func1() sending reply component=main reply=";; opcode: QUERY, status: NOERROR, id: 0\n;; flags:; QUERY: 0, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0\n\n;; ANSWER SECTION:\nhostname.local.\t3600\tIN\tA\t192.168.1.188\n"
DEBU[0002]github.com/LouisBrunner/avahi2dns/server.go:32 main.runServer.func1() sending reply component=main reply=";; opcode: QUERY, status: NOERROR, id: 0\n;; flags:; QUERY: 0, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0\n\n;; ANSWER SECTION:\nhostname.local.\t3600\tIN\tAAAA\tfe80::28b4:32ff:fe0f:38d0\n"

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.