Samba & Bonjour with Avahi

Okay, so you have a shiny new Linux box, and it’s running Samba, all nice and configured to share your files.  You have a Mac, and you want to use it with your nifty new Windows shares.  You can connect with Command-K in the finder, but it doesn’t show up in Finder under the Shared section.

You need Avahi.

I won’t bother going into the details of configuring Samba.  If you’ve not gotten that far, there are some pretty good resources out on the ‘net that will tell you how.  Where interacting with Bonjour is concerned, however, most of the references I found were flat wrong with modern OS X and Samba.

To make this work, the steps are simple (I’m running Ubuntu 12.04, so you may have to adjust accordingly for your Linux distro of choice).  The first step is to install Avahi:

root@core:/# apt-get install avahi-daemon avahi-utils

When this command completes, you’ll essentially have Bonjour running on your Linux box.  This has a number of advantages, most notably that you can now log into the thing by hostname (eg. core.local for my machine) without having to configure DNS.  But it still won’t allow you to browse shares in Finder; for that, you need a bit of configuration.

And so we move to step 2: create a file in /etc/avahi/services called smb.service, and place the following content in it:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
 <service>
   <type>_device-info._tcp</type>
   <port>0</port>
   <txt-record>model=RackMac</txt-record>
 </service>
</service-group>

Upon saving it, your new Linux box will happily appear in the Finder sidebar, and should all work.  You don’t even need to restart Avahi; it’ll pick up the new service file automagically.

There are other references out there for how to do this, but they all use port 139 – which doesn’t work.  I haven’t a clue when Microsoft changed the port number, but whatever; I don’t really care.  I have finder browsing goodness, so I’m happy.

Someday I may do a developer-oriented piece on the wonder that is Bonjour…

About Steve

When it comes to the desktop, Steve is a former Amiga, Windows, and Linux user, and as of six years ago, a die-hard Mac head (who, for once, isn't thinking of changing platforms again any time soon). When it comes to the server, Linux is pretty much the only game he plays. He also enjoys hardware hacking, and shouldn't be allowed near a keyboard after the sun sets (or for that matter, after it rises. Don't say I didn't warn you).
This entry was posted in Bonjour, Linux. Bookmark the permalink.

6 Responses to Samba & Bonjour with Avahi

  1. Michael Pender says:

    I’ve successfully set up netatalk to share the filespace from the Linux (Ubuntu) machine with my macs, and would like to set up screen sharing interface in the Finder now. Any ideas? I can use the connect to server option with vnc://ip.address to access the Linux machine, but I would like to access it like any other mac in the network. I was wondering if I can add an Avahi service?

    thanks, Mike.

  2. LarryJ says:

    I was forced to issue:
    sudo restart avahi-daemon
    after making the changes detailed here before my “shared folders” showed up on my wife’s iMac.

    Thanks for your help!

  3. Dan Dilloway says:

    Thanks for this info. Just what I needed, and still works in 2015 :-)

  4. Samir Borelli says:

    Thanks a lot!
    I was digging for some time to got this working.
    Now i’m looking for the same but for windows to see my smb, do you know somehow?

Leave a Reply

Your email address will not be published. Required fields are marked *