blog.masker.net
Setting Up Tftpd on OS X The Right Way

As a network engineer it is pretty hard to get around tftp. Sooner or later we end up needing some sort of tftp server on our laptops. One of the benefits of OS X is the BSD subsystem which contains a lot of these kinds of tools out of the box. In fact, OS X does ship with a tftp server and most of the tools you can find will be some sort of GUI interface to configure this built-in tftp server.

Unfortunately, the tftp server that ships with even the latest spin of OS X Lion is a bit archaic. The default build has no ability at all to create files on demand. It requires you to create every file and set anonymous write permissions before uploading. In this post, I’ll walk through setting up an alternative tftp server which does support the ability to upload new files via tftp.

Start out by installing MacPorts. If you haven’t needed to do this yet, you might as well get it out of the way because you will. Getting MacPorts installed is a bit beyond the scope of this post, but you can find installation instructions here.

Next, grab the latest copy of TftpServer, a GUI front-end for the tftp server built in to OS X. This little utility will make it easier to get things up and running and is great for managing the tftp server once it is installed. Open up the DMG and drag the TftpServer program into your Applications folder.

To install a more modern tftp server using MacPorts, open up a Terminal session and type the following:

sudo port install tftp-hpa +enable_upload +server

A brief word on MacPorts. MacPorts simplifies the process of downloading, compiling and installing open source software on OS X. There are several packages to choose from as well as the concept of variants. In the command above, we told MacPorts to install tftp-hpa, enabling the enable_upload and server variants. A variant is basically a set of configuration options to use when compiling and installing an application. The tftp-hpa package actually consists of a tftp client and server suite, so the +server tells MacPorts that we want to install not only the client, but also the server. The +enable_upload variant tells MacPorts that we want the tftp server to support anonymous uploading of files which do not already exist on the filesystem—the whole point of this exercise.

While MacPorts does its thing, go ahead and open the TftpServer application. You may get prompted for a password to do some initial configuration. If the server is running, click the ‘Stop TFTP’ button on the toolbar at the top. Click ‘Change Path’ and choose the folder you would like to use as your tftp repository. I just created a ‘tftp’ folder under my home folder and selected that.

You will see two sections having to do with permissions along the bottom of the TftpServer window. If either of these display a red warning, be sure to click the ‘Fix’ button. The tftp server will need very specific permissions set on the folder it uses to store files.

By now, hopefully MacPorts is done installing. If not, you will want to wait until it is finished before performing this last bit of configuration. Make sure the tftp server is stopped and then exit the TftpServer application. Open ‘/System/Library/LaunchDaemons/tftp.plist’ in your favorite text editor. You are looking for the section that looks like this:

        <key>ProgramArguments</key>
        <array>
                <string>/usr/libexec/tftpd</string>
                <string>-s</string>
                <string>/path/to/tftp</string>
        </array>

The ‘/path/to/tftp’ string will actually be the tftp folder you selected earlier. Replace the ‘/usr/libexec/tftpd’ string with ‘/opt/local/sbin/tftpd’ and add ‘<string>-c</string> immediately following this line. It will now look something like this:

        <key>ProgramArguments</key>
        <array>
                <string>/opt/local/sbin/tftpd</string>
                <string>-c</string>
                <string>-s</string>
                <string>/path/to/tftp</string>
        </array>

This change modifies the launchd plist for our tftp server to point to the newly installed tftpd and set a command line option that allows clients to upload new files.

That’s it! Save the file, open TftpServer and click the ‘Start TFTP’ button. You should now be able to tftp files up to your system even if the files have not yet been created. 

I’ve done some testing, and it appears that TftpServer simply ignores the changes to the path and parameters of tftpd in the launchd plist and still works quite effectively as a configuration tool to set the path or start and stop the service. Enjoy!

blog comments powered by Disqus