Bye CUPS: Printing with netcat
Turns out printing doesn't have to be hard
I recently migrated my daily laptop to FreeBSD. I have a networked HP LaserJet. After 10+ years of CUPS on Linux, I had been dreading setting up this printer on yet another machine. But the day came. I had to print quite a few documents so I decided to bite the bullet and setup printing on FreeBSD.
Off to the FreeBSD Handbook I went. Conveniently, they have a chapter on Printing. Given my past experience with CUPS, I figured this was going to be a treacherous journey so I read the entire document before getting started. Section 4 stood out:
Direct printing to network printers depends on the abilities of the printer, but most accept print jobs on port 9100, and nc(1) can be used with them.
nc netlaser 9100 < sample.txt
I had to read this several times. WTF. Use netcat? Surely I was missing some wizardry in the FreeBSD kernel that configured a network printer as some local network target aliased to netlaser, which handled all the printing magic for me. But how? Years of arbitrarily picking from a list of similarly named print drivers in CUPS prevented my brain from accepting what was written. I was confused. After trying to decipher the other sections in the document, I decided I would go for it.
nc 192.168.1.226 9100 < file.pdf
It. Just. Prints.
After 10+ years of Linux distributions pushing CUPS on me. Over a decade of this complex stack of drivers and daemons that I never quite trusted but “couldn’t live without.” FreeBSD comes along and is like “yeah, just use netcat.” And they’re right. Just use netcat.