Avahi Notes

From Noah.org
Revision as of 04:52, 22 March 2019 by Root (talk | contribs) (→‎Monitor from MacOS Bonjour)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


Monitor from MacOS Bonjour

MacOS uses Bonjour by default, so it's easy to get MacOS Bonjour and Linux Avahi talking to each other.

I have not yet figured out how to monitor all mDNS host announcements using MacOS, but if you are looking for a specific host to come up then the following will show when the given host, example.local adds or removes a published address.

dns-sd -G v4 example.local

You can test that from a Linux machine by running the following:

avahi-publish-address example.local 192.168.1.1

You may also browse for specific service announcements from any host. The following example looks fro SSH service announcements:

dns-sd -B _ssh._tcp

That may be tested from linux by running the following:

avahi-publish -s "SSH service" _ssh._tcp 22

Oddly, that does not give you the option to show the port that the service was advertised under, but once you have itdentified the name of the host you are interested in then you can request a lookup off all the information in the service announcement.

dns-sd -L "SSH service" _ssh._tcp

Note that the name used in the lookups and announcements is not necessarily the hostname of machine running the service. It can be any name you make up. What is more confusing is that the name used in address publishing and growing on the Mac side does represent a hostname.

dns-sd -G v4 example.local
# on the Linux side:
avahi-publish-address example.local 192.168.1.1
# on the MacOS side:
dns-sd -G v4 example.local

Monitor From Linux

Monitor Zeroconf advertisements:

avahi-browse --all --resolve

To look for just SSH services use the following command. Note the rather cryptic type name that you must use. You may also find it useful to add the --resolve option.

avahi-browse _ssh._tcp
avahi-browse --resolve _ssh._tcp

The --dump-db option is almost totally useless since it lists the human readable names of the service types, but it does not give you the actual name that you need to use to browse that service. For example, --dump-db will list SSH Remote Terminal as one of the service types, but to actually browse for that service you need to use the type name of _ssh._tcp, which is a name I will never remember. You can't use --dump-db to remind yourself of this.

GUI browser

The avahi-discover package has a simple GUI browser. This is the equivalent of the command-line tool avahi-browse.

publish

If you want to temporarily publish or annouce a service you can use the avahi-publish.

The following example shows how to publish that a VNC server is available for a KVM guest on port 5900.

avahi-publish -s "KVM guest VNC for $(hostname)" _rfb._tcp 5900 "KVM guest with VGA screen via RFB (VNC)."

You would look for this announcement from another machine with the following command.

avahi-browse _rfb._tcp --resolve

If the avahi-publish is running then you should see something like the following (assume the publishing machine's hostname is vmhost-1).

+   eth3 IPv4 KVM guest VNC for vmhost-1                    VNC Remote Access    local
=   eth3 IPv4 KVM guest VNC for vmhost-1                    VNC Remote Access    local
   hostname = [vmhost-1.local]
   address = [10.0.0.151]
   port = [5900]
   txt = ["KVM guest with VGA screen via RFB (VNC)."]

avahi-daemon

If you want Avahi to publish your SSH service you must create a service config for it. You can usually just copy the example one and use it without editing it.

cp /usr/share/doc/avahi-daemon/examples/ssh.service /etc/avahi/services/.

If that example is not available then the following should work if copied to /etc/avahi/services/ssh.service.

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_ssh._tcp</type>
    <port>22</port>
  </service>
</service-group>

Avahi daemon won't start

If you look in /var/log/syslog you may see errors like the following when trying to start or restart avahi-daemon.

Oct 23 20:09:55 vmhost-1 avahi-daemon[15328]: avahi-daemon 0.6.31 starting up.
Oct 23 20:09:55 vmhost-1 avahi-daemon[15328]: dbus_bus_get_private(): Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
Oct 23 20:09:55 vmhost-1 avahi-daemon[15328]: WARNING: Failed to contact D-Bus daemon.

This can happen if you updated your network settings. This causes D-Bus to crash without logging any information. The solution is to start D-Bus again.

service dbus start