NetBSD Documentation: Printing to a remote SMB printer from NetBSD

How to print from a NetBSD machine to a printer connected to an MS Windows machine (or other machine using SMB to share a printer).

Printing to a remote SMB printer from NetBSD

Printing to a remote SMB printer from NetBSD


The setup described below has been used for several years to print PostScript documents from a NetBSD machine to an HP Laserjet 4L connected to a MS Windows PC. This gives an example of both 1) calling GhostScript to translate PS output into something a non-PS (in this case HP-PCL) printer understands, and 2) setting up /etc/printcap so that things printed with lpr will go to a remote printer that speaks SMB.


The following steps, if you haven't done them already, are necessary before you can set up printing to a remote SMB printer from NetBSD:

  1. Install the net/samba package.
  2. If your printer is not PostScript, and you'll be wanting to print PostScript files (ie, your application produces PostScript output), install the print/ghostscript package.

Setting up remote printing using samba

The following steps should allow you to print to a remote printer from NetBSD, using samba to share it.

  1. Put the file "smbprint" in /usr/local/bin, and make it executable.
  2. Create a printcap entry for each remote printer similar to the example in the file "printcap" included here.
  3. Create a directory /etc/lpd/PRINTERNAME for each remote printer, and put a config file there similar to the one in the example file "config" here.
  4. Create the spool directories you specified in your printcap entries.
  5. Make sure you can connect to the printer on the remote machine manually with:
    smbclient //machinename/printername
    If you receive the smb: \> prompt, you're probably good to go. If not, you may need to add a "-I ip-addr" argument to the smbclient command in /usr/local/bin/smbprint. It is recommended that you figure out how to derive the ip address from the remote machine's SMB name with nmblookup, so that you won't have to hardcode the address (thus making the script useful for only a single printer).
  6. Try printing something. Remember, if you've specified a gs device in the config file, you must call lpr with a PostScript file. Either pipe the output of some program like a2ps to lpr, or print out one of the PostScript examples included in the Ghostscript distribution.
  7. Note that you can specify two different entries in your printcap, one that translates through Ghostscript, and one that sends the output untranslated (point them at different config directories, and give the same "server=" option, but different "device=" options). This way you can send things in the printer's native language (eg; PCL) or plain ASCII when needed, and still have a print device to give to programs that produce PostScript output.

Back to NetBSD Documentation: Miscellaneous