# MdnsLite

[![Hex version]( "Hex version")](

MdnsLite is a simple, limited, no frills implementation of an
[mDNS]( (multicast Domain Name System)
server. It operates like a DNS server, the difference being that it uses multicast
instead of unicast and is meant to be the DNS server for the _.local_ domain. MdnsLite
also provides for the advertising (discovery) of services offered by the host system.
Examples of services are an HTTP or an SSH server. Read about configuring
services in the Configuration section below.

MdnsLite employs a network interface monitor that can dynamically adjust to
network changes, e.g., assignment of a new IP address to a host. The current
version of MdnsLite comes with an `InetMonitor` which periodically checks via `inet:getifaddrs()`
for changes in the network. For exmaple, a change could be the re-assignment of IP addresses. For configuration values related to the interface monitor, please see the Confgiration section below.

MdnsLite recognizes the following [query types](

* A - Find the IPv4 address of a hostname.
* PTR - Given an IPv4 address, find its hostname - reverse lookup. If, however, it receives a request domain of
"_services._dns-sd._udp.local", MdnsLite will respond with a list of
every service available (and is specified in the configuration) on the host.
* SRV - Service Locator

If you want to know the details of the various DNS/mDNS record types and their fields,
a good source is

There are at least a couple of other Elixir/Erlang implementations of mDNS servers:

1. [Rosetta Home mdns]( (Elixir)
2. [Shortishly mdns]( (Erlang)

These implementations provided valuable guidance in the building of MdnsLite.

## Configuration

A typical configuration in the `config.exs` file looks

config :mdns_lite,
  # Use these values to construct the DNS resource record responses
  # to a DNS query.
  host: :hostname,
  ttl: 120,
  services: [
    # service type: _http._tcp.local - used in match
      name: "Web Server",
      protocol: "http",
      transport: "tcp",
      port: 80,
    # service_type: _ssh._tcp.local - used in match
      name: "Secure Socket",
      protocol: "ssh",
      transport: "tcp",
      port: 22,

(Note that the configuration changed from v0.2 to v0.3, eliminating a superflous map.)

The values of `host` and `ttl` will be used in the construction of mDNS (DNS) responses.

`host` can have the value of  `:hostname` in which case the value will be replaced with the value of `:inet.gethostname()`, otherwise you can provide a string value. You can specify an alias hostname in which case `host` will be `["hostname", "alias-example"]`. The second value must be a string. When you use an alias, an "A" query can be made to  `alias-example.local` as well as to `hostname.local`.

`ttl` refers to a Time To Live value in seconds. [RFC 6762 - Multicast
DNS]( - recommends a default value of 120 seconds.

As mentioned above, `MdnsLite` uses an interface monitor. `InetMonitor` is currently the only monitor available.
The configuration value `ip_address_monitor` (not shown) defaults to `Mdns.InetMonitor`. And the configuration value `excluded_ifnames` represents those interfaces that the `InetMonitor` will **not** watch. Its default value is ["lo0", "lo"].

The `services` section lists the services that the host offers,
such as providing an HTTP server. You must supply the `protocol`, `transport` and
`port` values for each service. You may also specify `weight` and/or `host`. They each default to a zero value. Please consult the RFC for an explanation of these values. 

## Installation

If [available in Hex](, the package can be installed
by adding `mdns_lite` to your list of dependencies in `mix.exs`:

def deps do
    {:mdns_lite, "~> 0.4"}

## Usage

`MdnsLite` is an Elixir/Erlang application; it will start up automatically when
its enclosing application starts.

When MdnsLite is running, it can be tested using the linux `dig` utility:

$ dig @ -p 5353 -t A nerves-7fcb.local  
nerves-7fcb.local. 120	IN	A  
$ dig @ -p 5353 -x  
... 120	IN	PTR	nerves-7fcb.local.  
$ dig @nerves-7fcb.local -p 5353 -t PTR _ssh._tcp.local  
_ssh._tcp.local.	120	IN	PTR	nerves-7fcb._ssh._tcp.local.  
nerves-7fcb._ssh._tcp.local. 120 IN	TXT	""  
nerves-7fcb._ssh._tcp.local. 120 IN	SRV	0 0 22 nerves-7fcb.local.  
nerves-7fcb.local.	120	IN	A  
$ dig @ -p 5353 -t SRV nerves-7fcb._ssh._tcp.local  
nerves-7fcb._ssh._tcp.local. 120 IN	SRV	0 0 22 nerves-7fcb.local.  
nerves-7fcb.local.	120	IN	A  

Although `dig` is a lookup utility for DNS, it can be used to query `MdnsLite`. You can use the reserved ip address (``) and port(`5353`) and query the local domain. Or you can use the local hostname, e.g., `nerves-7fcb.local` of the host that is providing the mDNS responses along with port`5353`.  

Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at [](