Thursday, July 07, 2016

How to enable tftpd or TFTP service on OS X or Mac

I needed to update firmware on a TP-LINK router on a recent trip. One option is to download the firmware bundle and place it on a TFTP server accessible by the TP-link router. At the time, I had only a MacBook Pro running OS X 10.11.5 (El Capitan). 

Knowing OS X is BSD-based, I assume tftpd or tftp service is baked in. It is! Googling yielded a few articles on how to enable tftpd or tftp service on Mac or OS X. None is immediately reusable, by which, I mean to copy+paste :-)

To benefit those who wants to run TFTP service on Mac or OS X, below is a simple MOP that worked for me. The instructions below assume you have a terminal open already.

  • to enable and run tftpd or tftp service. '-F' to ignore the Disabled key for the service.

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist


  • to verify it is running properly
    • to add a test file into the /private/tftpboot/, which is the tftp service root directory.

date > /tmp/test1

sudo cp /tmp/test1 /private/tftpboot/

    • to run tftp client program to retrieve the test file
tftp localhost

get test1

quit

  • to serve any file via TFTP service now running on your Macbook, simply copy it to /private/tftpboot/
sudo cp file2 /private/tftpboot/
  • to clean-up
    • to purge files you no longer wants to serve.

sudo rm /private/tftpboot/test1

    • to unload the service configuration and stop the tftpd or tftp service

sudo launchctl unload /System/Library/LaunchDaemons/tftp.plist


The above assume you need tftpd or tftp service just to run one time or other ad-hoc purposes. If you like to keep tftpd running, you may need to load the tftp service configuration using a different option. Namely, '-w' instead of '-F', to override the Disabled key for the service.
sudo launchctl load -w /System/Library/LaunchDaemons/tftp.plist