FreeBSD and Mac OS X: a happy combination

I notice that most of my readers’ homes consist of one/more FreeBSD server(s) and one/more Apple computer(s) running Mac OS X. In this post I will introduce the multicast DNS and service discovery concepts. Both are very will suited for a workstation running Mac OS X and a home server running FreeBSD. In the previous blog post I showed how you could use FreeBSD as a Time Machine backup and now I’m going to show you how to make your FreeBSD look like an Apple Xserve. :-)

I assume familiarity with FreeBSD administration and some networking concepts.

What is Multicast DNS?
Multicast DNS is a recent protocol for doing DNS in a non centralized way, i.e., with multicast DNS, you can have a bunch of machines replying and querying hostnames ending in “.local”. Each machine is responsible for telling the others its hostname.
So, if machine A pings B.local, A will query B.local (via multicast) and B.local will reply to A. This should require no configuration from the user.

You can see that this model scales well and is convenient to have on a local network.

Service Discovery?
It would be cool if you could simply pick a computer from a list instead of memorizing its IP address, wouldn’t it? Several applications under Mac OS X allow this. If you use Mac OS X Leopard, you probably have already noticed that there are several network shares automatically added to the Finder list. This is Bonjour in action. Bonjour is what Apple calls Multicast DNS combined with Service discovery.

Multicast DNS implementations
Mac OS X comes with a multicast DNS implementation called mDNSresponder, but we won’t be using it with FreeBSD. Instead, we’ll use avahi, which I prefer.

First steps with Avahi
If you use FreeBSD as a workstation, you probably already have avahi installed. If not, simply do:

# portinstall avahi

After this, avahi is installed and ready to work. After enabling it in “/etc/rc.conf”, try giving it a try (yes, without configuring anything):

# /usr/local/etc/rc.d/dbus start
# /usr/local/etc/rc.d/avahi-daemon start

Right-click or Hold-click on the Mac OS X Terminal dock icon. You should see the menu entry “New Remote Connection…”. Click on it. You should see your FreeBSD server on the list:

Isn’t this cool? BTW, the key combination for this is Shift+Command+K.

So, how did this work? Check the directory “/usr/local/etc/avahi/services” on your FreeBSD system. It contains several XML files describing the service. The XML files themselves are very easy to write, just look at ssh.service.

Safari works with Bonjour too, so let’s try it. Go to Preferences and in “Bookmarks Bar” check “Include Bonjour”. You should now have a “Bonjour” folder like button on the Safari Bookmars Bar. 

You can configure a regular web server if you have one, but I don’t. What I have is mldonkey with a web interface. The following service description makes an mldonkey bookmark show up on the Bonjour list of my Safari and a Telnet entry show up on the Terminal:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

  <name replace-wildcards="yes">%h mldonkey</name>




If you changed the port to 80, it would connect to a regular HTTP server on the FreeBSD system.

And this is what shows up on Safari:

BTW, Camino supports Bonjour too.

On to Bonjour file sharing

For the file sharing service, you need to install netatalk port which supports AFP (Apple File Sharing)

# portinstall netatalk

Then enable it in rc.conf (all you need is afpd running):


And start it:

/usr/local/etc/rc.d/netatalk start

I use the following service description:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

  <name replace-wildcards="yes">%h</name>




Reload avahi:
# avahi-daemon -r

And now you should see something like this in the Finder:

Of course I promised it would look like an Xserve, so all you need to do is change “PowerMac3,5″ to “Xserve” and you’ll have your well earned $3000 Xserve :-)

If you don’t really want an Xserve, pick one from the list:

  • Xserve (or RackMac)
  • PowerBook
  • PowerMac
  • PowerMac3,5
  • Macmini
  • iMac
  • MacBook
  • MacBookPro
  • MacBookAir
  • MacPro
  • AppleTV1,1
  • AirPort


Finally, there are other services for which Apple uses Bonjour, namely, Screen Sharing (VNC) and Remote Speakers (AirPort Express), but I haven’t played with these.

I hope you enjoyed reading this, thanks.

7 thoughts on “FreeBSD and Mac OS X: a happy combination

  1. Pingback: FreeBSD and Mac OS X: a happy combination |

  2. Pingback: FreeBSD + OSX Filesharing Summary : DDEREK

  3. Thank you so much, I find these macosx + freebsd integration tips very useful. BTW, if you use pf, you might need to add a rule like this one to allow multicast traffic: pass out quick on $int_if inet proto udp from $localnet to $mcast allow-opts

  4. This is an excellent post on a topic important to me. Our small web apps company is moving from one Windows server to an Apple Xserve and a FreeBSD server very soon. We have to get up to speed on getting these to work very well together, so I’m setting up FreeBSD on several machines at home/office first, one as a firewall and another as a fileserver, etc., to talk with our Leopard clients. Thanks!

  5. thanks SO much for this!

    i’m a long-time freebsd admin, relatively green mac user. i’ve been using nfs and samba; i’ve never even thought about better integration – but now can’t wait to try it!

  6. Thank you for blogging on OS X + FreeBSD! Please keep these posts coming. I’ve bookmarked you and will keep up.

    Our small Web apps company has fully moved from Windows servers to our Apple Xserve with Leopard Server. We still have the killer PC server that was running Windows this past year. so we’ve gone with FreeBSD to compliment OS X. I’ve only been doing UNIX seriously for the past year or so, and it’s a small part of what I do (both at work and home). So thanks again!

Comments are closed.