9

First, some background: We've got a lab containing a handful of dedicated Linux servers that run on an isolated LAN. All the servers run the same OS (Debian Linux) and the same proprietary server software, and the server processes communicate with each other to keep their data in sync. That means that as far as any clients are concerned, it doesn't matter which server the client connects to -- any server will return the same data as any other.

These Linux servers all run avahi-daemon to publish mDNS hostnames for themselves, which means that a client can enter e.g. "http://linux-server-1.local." into his web browser and connect to Linux server #1, and so on.

This is all well and good, except it means that a user sitting at the client machine (typically a Mac or Windows laptop with Bonjour installed) has to know (or figure out) which of the Linux servers are currently online, and he has to make sure he connects to one of those. For example, if server #2 is offline today, and the client enters "http://linux-server-2.local." into his URL bar, he's not going to get a response. That isn't the end of the world, of course, but it is annoying for newbie users who expect everything to "just work", and also it makes the development of robust client-side scripting more complicated (since the client-side script would need to know how to deal with offline servers explicitly).

With that in mind, my question is this: is it possible to configure Avahi to publish an anycast-style mDNS hostname alias as well? The goal is that anyone could sit down with his laptop, enter "http://any-linux-server.local." (or similar), and get connected to one of the servers that is currently on line (again, it doesn't matter which one).

Note that this needs to work without any special configuration of client laptops, as we have no control over them (other than the requirement that they have Bonjour installed).

Also note that we can't rely on the presence of a separate nameserver or proxy box, or on the presence of any particular Linux server, since that would introduce a single point of failure, which we're trying to avoid.

Jeremy Friesner
  • 1,311
  • 1
  • 14
  • 25

1 Answers1

13

Trent Lloyd here, one of the authors of the Avahi project.

This is in theory possible, but it is not easy to do. Unfortunately the default mechanism for publishing a hostname in Avahi, also published a reverse-DNS record which is listed as exclusive. Thus if you try and publish 2 hostnames pointing at the same IP, you get a conflict on the reverse DNS record.

It is possible to do this if you use the Avahi API to manually publish an A record, and mark it as non-exclusive. You would have to write a small background process for each server in Python, C or similar.

The API call to use is avahi_entry_group_add_record, and you need to pass AVAHI_PUBLISH_ALLOW_MULTIPLE into the flags field. This should then work.

An alternative is to use the service discovery in the way it was intended, and have each client publish a HTTP service, and use a firefox plugin or similar to browse announced web services. Or some other kind of service browser.

Bonjour used to include a plugin for Internet Explorer to do this like a bookmarks bar, I am not sure if it still does.

Trent Lloyd
  • 450
  • 4
  • 7
  • 2
    I got it to work, thanks! In case anyone is interested, I've posted the C source code here: https://public.msli.com/lcs/jaf/publish_cnames.c – Jeremy Friesner Jun 03 '11 at 22:56
  • hm. that doesn't seem to work with more recent versions of avahi :( The program prints that it has successfully published the names, but they don't show up when browsing from another host on the network. – Frederick Nord Sep 17 '15 at 08:00