FreeBSD, CUPS and iPad printing

From ZS64
Jump to navigationJump to search

For a long time, I've struggled getting CUPS to work properly between my FreeBSD server and my Macs. I think I've finally figured it out.

FreeBSD Packages

I've installed these packages:

  • print/cups-base
  • print/foo2zjs (because I have a Samsung CLP 315; you might need a different driver package for your printer)
  • net/avahi (as part of the larger Gnome packages)

CUPS Configuration

The first task is to get CUPS to talk to the printer. Actually, the first task is to let cupsd accept commands from your browser. So open up /usr/local/etc/cups/cupsd.conf, and add Allow all to the <location /> block:

<Location />
  # Allow remote access...
  Order allow,deny
  Allow all

While you’re at it, add this line, for example near the top of the file:

ServerAlias *

(CUPS, being an HTTP server, respects the Host: header in HTTP requests. Unfortunately, it doesn't really know about the Bonjour domain, so it rejects requests for host names that it thinks do not belong to the server, making print requests from Bonjour clients fail. Unless you're planning to set up a cluster of load balanced CUPS servers, ServerAlias * should just work fine to make CUPS feel responsible for any and all print requests that find their way to the server.)

Adding The Printer

Point your browser at http://yourserver:631 and navigate to the administration page. Click the Add Printer button there. At this point, your browser should ask you for a username and passwort. You'll need to log in with a system user that is in the wheel group.

  1. The first step in the Add Printer wizard has you select how CUPS will be communicating with the printer. My Samsung CLP 315 is hooked up via USB to a cheap network print server that speaks the plain TCP stream protocol on port 9100 (also known as JetDirect), so I selected that, and entered the URL: socket://hostnameofmyprintserver:9100.
  2. Next enter a name, a description and a location for this printer. The name is the queue name that you will use from the command line as well as from other IPP clients, so pick something short and meaningful, and easy to type. IPP clients like Macs show the description and location information to help you identify a particular printer; it's only ever displayed, and you never need to enter these into a client, so feel free to type away to your hearts content. Also make sure you check Share this printer to make it available on the network.
  3. The final step is to select the appropriate printer driver: first pick the maker, then try to find the model, or a close approximation. The Open Printing Printers List may help finding the right entry.
  4. After clicking Modify Printer, you should be presented with a short success message, and then be taken to the admin page for your newly created printer. From the Maintainance menu, pick Print Test Page to make sure that you can actually print successfully. If this fails, it's down to parsing error logs (/var/log/cups) and Googling.

Enabling Remote Printing

From CUPS’ main Administration tab, check the two options Share printers connected to this system and Allow printing from the Internet, then click Change Settings. If you feel this will actually allow random people on the internet to print to your printer (because you don't have a firewall in front of your server), you'll need to read and apply the documentation for the Allow and Deny directives in cupsd.conf.

Printing from a Mac

If you have a Mac, you can use it to test network printing.

  1. Add a new printer, using the Internet Printing Protocol (IPP) protocol, enter the IP address or DNS name of your server, and the name of the printer queue on the server. It took me a long time to figure out that the queue name you have to enter here is actually the local part of the IPP URL! So if your printer name on the server is clp310, you need to enter /printers/clp310 here.
  2. Next, pick a printer driver for the new printer, and hit Add.
  3. Depending on your printer model, you might be asked to select which optional parts your printer has (like extra memory, additional trays or a duplex unit).

Now you're ready to print a test page from your Mac. Simply hit TextEdit or similar.

After having tested printing successfully, you can remove the printer again, as we're about to enable automatic discovery.

Enabling Auto-Discovery

The final step is to enable your new network printer to be auto-discovered through the magic of Bonjour. CUPS should be able to tell avahi (the Bonjour agent) that information automatically, but that option appears to be broken in CUPS 1.4.6. Luckly, you can easily tell avahi what to announce:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
		<txt-record>ty=Samsung CLP 315</txt-record>
		<txt-record>adminurl=htt p://yourservername:631/printers/clp310</txt-record>
		<txt-record>note=Wohnzimmer Cat & Stefan</txt-record>
		<txt-record>product=Samsung CLP 315</txt-record>

In /usr/local/etc/avahi/services, create a new file myprinter.service (the actual name does not really matter), and paste the above. Of course, you will want to change a couple of entries in there:

  • name: whatever you want displayed on the client. However, it's limited to certain characters.
  • rp=printers/myqueuename: the local part of the IPP URL for your printer
  • ty=SomePrinterModelName: a string identifying your make and model of printer; I'm not sure any client uses this acutally
  • product=SomePrinterModelName: same as ty.
  • adminurl=fullUrlOfCupsAdminPage: the full URL for the admin page for your print queue. You can go there in your browser, but clients can issue special requests to manage the queue and query it's status.
  • note=aNoteToDisplay: random text that helps a user to identify this printer; basically the same information as the location for the printer in CUPS.

Save the file; avahi will pick up the (new) contents automatically. To see if the announcement has been registered, run avahi-browser -t _ipp._tcp; that will show you all printers being announced on your network.

And you’re done! Bonjour clients should now see the printer, and should be able to print to it.