Printer sharing between Windows and Linux

Figure out how to connect your Windows machines to a shared printer as a network device from your Linux box in this tip.

The less you need to rely on any proprietary protocol to get work done, the better off you are overall. Some of...

those protocols have been real stumbling blocks -- such as SMB, Microsoft's proprietary protocol for file and printer sharing. Linux implementations of SMB exist, but you're probably better off without it in the long run whenever you can manage it.

More on file/print sharing:
Using Samba for file/print sharing needs

RHEL4 and Windows integration using Samba-3 

I recently set up a Linux workstation that shared out a Hewlett-Packard printer to the rest of my network -- a network that otherwise consisted entirely of Windows machines. I didn't like the idea of setting up SMB support on the Linux box, and instead, explored the possibility of having the Windows machines connect directly to the shared printer as a network printing device.

To my surprise, this turned out to be pretty easy. Here are the steps to connect your Windows machines to the shared printer:

  1. Set up the printer on your Linux machine and share it using CUPS via port 631. The exact method for doing this varies between distributions, so check with your distro's documentation. The end result should be a working printer, and a running CUPS service which you can access through your Web browser at http://localhost:631 from the Linux system.

  2. Using the CUPS Web interface, go to the Printers tab and make a note of the printer name, which is typically the Description: line). You can do this from the Windows machine where you plan to set up printer support.

  3. In Windows, go to Control Panel | Printers and click onAdd a printer.

  4. When prompted for a printer location, select Network printer, in the Add Printer Wizard.

  5. When prompted for the network location, select URL and use the following URL format: http://<hostname>:631/printers/<printername>.

    For instance, if the Linux host has a DNS name of linuxbox and the printer is named LaserJet-5, you'd use http://linuxbox:631/printers/LaserJet-5 as the URL.

  6. When asked for a printer driver, select Generic as the manufacturer and MS Publisher Imagesetter as the driver. In truth, any generic PostScript driver will do, but this works as well as any.

  7. When finished with the wizard, print a test page to make sure everything is set up correctly.

In Windows Vista, the steps are almost exactly the same, but the nomenclature for some of the steps is a little different. In the first step of the wizard, Vista will attempt to search for a printer (via SMB, which it won't find). Click Stop to halt the search and then click The printer that I want wasn't listed to add a printer manually.

In the next step of the wizard, use Select a shared printer by name when you want to supply the printer's URL. The rest should unfold exactly as before. Adding a printer by TCP/IP address or hostname will not work. Finally, if you're using a firewall product, make sure that port 631 is not being blocked. The Microsoft firewall on the Windows machine will usually know automatically what to do, but some third-party products may not.

If you're managing a workgroup and using system images to deploy your desktops, you can use the Windows con2prt utility, or a freeware substitute like AdPrintX, as a way to automate adding references to a CUPS-managed printer. If you're dealing with multiple CUPS-driven printing systems on the Linux side, you may want to drop the cash for the CUPS Companion CD and its accompanying book. The CUPS Companion CD is now offered in lieu of the commercial UNIX printing product ESP Print Pro, which is being discontinued by the manufacturer.

Have a question or comment about the tip? Email us. And don't forget to visit our new blog, the Enterprise Linux Log.

Dig Deeper on Linux servers