Publishing extra mDNS hostname with Avahi

Background

My NAS has two ethernet interfaces. One is connected to my usual network, another is connected to my workstation directly. The problem is the latter one, as it's not a conventional "network".

I was able to automate the connection process using DHCP, but making actual connection still requires punching in IP addresses, which is not human-friendly. I don't want to remember those arbitrary numbers.

So, to avoid using IP, I want to assign a separate domain name to the new interface.

References

A little bit of Journey

At first, I wanted to setup Avahi to serve different name over each interface, but some web searching suggested it's not possible by design. Opening up the Avahi config file(/etc/avahi/avahi-daemon.conf) does prove the point. There's no such thing as per-interface setting nor multiple name.

Someone suggested changing /etc/avahi/hosts, but I couldn't make it work. Come to think of it, this should fail because of the collision b/w reverse mDNS entries, which maps IP to mDNS hostname. You can't have two different name for the same IP address.

The solution

Somehow, I came across with a utility called avahi-publish. Its help message looks like this:

avahi-publish [options] -s <name> <type> <port> [<txt ...>]
    ...
    -a --address         Publish address
    ...
    -R --no-reverse      Do not publish reverse entry with address
    ...

This pretty much can satisfy my needs, especially --no-reserve part.

So, running the following on the server will add a custom hostname:

avahi-publish -avR direct-maru.local 192.168.100.1
# This process keeps running.

... which can be tested on another machine:

avahi-resolve direct-maru.local

Note that, I initially tried direct.maru.local, but it didn't work. Avahi accepts only .local domains by default, which mean it even reject any sub-domains like *.maru.local. Since the goal here is to minimizing client configuration, I decided to stick with .local domain.