Entries Comments



Advertising Linux Services via Avahi/Bonjour

27 January, 2008 (16:20) | Linux, Mac, Networks | By: benjamin

Update: most of this information is still correct but an update for combining service definitions into one file and setting an icon is available here: http://holyarmy.org/2008/11/bonjour-avahi-addendum

In my last post I outlined how I followed others’ directions to enable netatalk on Linux and Time Machine backups to a shared AFP folder. Originally, I also described how to put all your shares on netatalk. I suppose if only have Mac clients or you REALLY want to use AFP, you can do so. As I worked with files over AFP shares, I started noticing that the performance seemed to be quite bad. No, I didn’t benchmark, but copying large video files to a shared folder over my gigabit network was substantially slower over AFP (netatalk) than over CIFS/SMB (samba). I use my network shares pretty heavily, so this was a concern. Also, netatalk tries very hard to replicate an HFS filesystem complete with resource fork support. This means that your shared directories end up with lots of extra folders named “.AppleDouble”(and a few others) containing Mac specific info. (Note: even on CIFS you’ll get the “.AppleDB” folders unless you disable a setting in Finder. I can deal with .AppleDB better than .AppleDouble AND .AppleDB) So, because of these two issues I decided to try using CIFS and samba again.

My first experiment was to try sharing a “time_machine” folder via CIFS, and using the “defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1″ hack on the previous post, I was able to get Time Machine to perform a backup. It worked, but in the end I decided that if I need to restore from this backup, I want my resource forks intact. To do that, I need AFP and netatalk. So, I removed all AFP shares except the one for Time Machine backup share. Now my Time Machine would backup and restore happily, and I could again use my Samba shares.

One of the cool things about having used AFP/netatalk was that my server and folders were showing up in my finder window. Well, that’s not a feature of AFP or netatalk, its actually avahi/Bonjour doing that. So, all I had to do was advertise the services. If you followed my previous posts, you’ve already created a service for AFP/netatalk on your server; it’s simple to create more, just add more service files. I’ll paste in all of my service files here:

/etc/avahi/services/aftp.service/

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

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

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

samba.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>_smb._tcp</type>
<port>139</port>
</service>
</service-group>

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

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

So, you can see that I’m announcing Samba/CIFS file, AFP file, Apache HTTPd, VNC (RFB) Remote Desktop, SSH and SFTP services. Leopard’s Finder only displays the CIFS, AFP and RFB services, but other applications with Bonjour support will see the other services. By default Finder opens “Screen Sharing” when you use the advertised service, but Chicken of the VNC can also browse for Bonjour enabled VNC servers. Below are screen shots of my Finder showing the shared services.

finder_bonjour_vnc.jpg
finder_bonjour_cifs.jpg
finder_bonjour_cifs.jpg

No restarts are needed for anything at this point. The services should automatically be picked up by the Linux avahi daemon, but if you really need to, you may execute /etc/init.d/avahi-daemon restart .

Comments

Comment from George Brownlee
Time: April 25, 2008, 3:45 pm

Have a look at
http://www.simonwheatley.co.uk/2008/04/06/avahi-finder-icons/

He’s figured out how to specify the icons displayed in the finder pane, i.e. AirPort Express, eMac, iMac etc

Comment from Benjamin
Time: April 25, 2008, 4:35 pm

Good stuff, George. Thanks for the link!

Pingback from RayRay Is Forever » Blog Archive » Avoid OSX Metadata on Network Shares
Time: June 11, 2008, 12:19 am

[...] services that you want to appear in Finder, Terminal, and other places automagically, check out HolyArmy.org Posted in Personal Updates, Server Blog [...]

Pingback from Ubuntu als Mac | Bruis blog
Time: October 5, 2008, 5:09 am

[...] Advertise your services Laat Avahi je services over het netwerk verspreiden, bonjour zal het geweldig [...]

Comment from Farhad Khan
Time: October 26, 2008, 8:28 am

I tried the service descriptions above but for some reason I can never get ssh to show up as a sevice in dns-sd or Bonjour. HTTP worked fine. Do you know why?

Pingback from Benjamin Sherman » Bonjour Avahi Addendum
Time: November 6, 2008, 9:23 am

[...] while back I wrote about advertising Linux services via Avahi/Bonjour. Since then I’ve made a few changes to my [...]

Comment from benjamin
Time: November 6, 2008, 9:26 am

Farhad,

See my latest post for a better way to list services: http://holyarmy.org/2008/11/bonjour-avahi-addendum/

But regarding SSH showing up, it doesn’t in Finder’s Bonjour view, but I was able to see it using the command-line program dns-sd in Terminal.

$ dns-sd -L myserver _ssh

Hope that helps!

Ref:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dns-sd.1.html

Comment from matt
Time: November 16, 2008, 10:23 pm

If you want gui, you can see all the linux advertised services from a Mac using Bonjour Browser
http://www.tildesoft.com

Pingback from Ubuntu and Mac OS X Integration – blog.scottlowe.org – The weblog of an IT pro specializing in virtualization, storage, and servers
Time: January 2, 2009, 8:36 am

[...] systems running Avahi or Macs. I’d installed Avahi earlier and used some service definitions from this article and this blog post to advertise Samba and HTTP. In addition, after installing Firefly, I’d [...]

Comment from aj Slater
Time: April 18, 2009, 1:54 pm

Actual mac servers combine all the services into one service group with the same name. This lets the leopard finder combine like services into one icon. This is most apparent when you have afp, samba (avahi), and samba broadcasting its NetBIOS name. If you make them all one service group with the same name (same as the NetBIOS name ‘%h’) The Leopard finder will show only one icon and preferentially use afp over samba over finding samba via NetBIOS.

Also you can specify your finder icon for a service group like so:
http://www.simonwheatley.co.uk/2008/04/06/avahi-finder-icons/

Comment from benjamin
Time: April 19, 2009, 7:04 pm

Thanks for commenting!

You are very correct, I should probably update this post to reference my update post about just that topic. ( http://holyarmy.org/2008/11/bonjour-avahi-addendum/ )

Cheers!

Pingback from Setting up a home NAS using OpenSolaris and ZFS | Morph3ous’s Weblog
Time: August 30, 2009, 4:42 pm

[...] the XML files that tell MDNS what to advertise. (Found this information from here, here, and [...]

Pingback from Using MDNS to advertise OpenSolaris NAS to Mac computers | Morph3ous’s Weblog
Time: September 5, 2009, 12:20 pm

[...] the XML files that tell MDNS what to advertise. (Found this information from here, here, and [...]

Pingback from Install AFP with SSL
Time: March 23, 2010, 10:34 am

[...] might also want to advertise the server with Bonjour. I followed these [...]

Pingback from OpenSolaris + TimeMachine backup + network discovery « Matt Connolly’s Blog
Time: May 7, 2010, 2:33 pm

[...] If you’re interested in advertising other services so that they are discoverable by the Mac, this is a great article (it’s for linux, but the avahi side of things is the same using avahi-bridge): Benjamin Sherman » Advertising Linux Services via Avahi/Bonjour. [...]

Comment from David Österberg
Time: February 11, 2012, 6:43 am

Thanks for this. In order to get Samba sharing to work on Mac OS X Lion I had to change port number to 445. As was described at http://tob.io/post/8383529336/fix-avahi-samba-with-os-x-lion

samba.service

%h

_smb._tcp
445

Comment from Tim Harper
Time: December 31, 2012, 9:43 am

I echo David Österberg’s comments. This is the configuration that worked for me: http://pastie.org/5602895

Write a comment