Sharing Printers and Drivers Over a Heterogenous LAN
I wanted to set up a networked printer that was accessible from any computer on my LAN, which includes Linux, Mac, and Windows machines. The easy solution would be to buy an explicitly networkable printer, but I already had an an old HP PSC-1210 multifunction printer. A little research showed that it should be possible to share this via CUPS and Samba. This article details how I accomplished this.
Set up a Print Server
First you need to select a computer to act as your print server. This computer will need to be running in order for the printer to be accessible, so I selected a mac mini running CentOS 5.1, for its low power consumption.
After installing CUPS, I edited the configuration to allow access on the lan. I also wanted to allow access to the admin web pages from the LAN, since the server was headless.
# Listen for connections on port 631.
Listen <hostname>:631
# Allow computers on the LAN to access the server.
<Location />
Order Deny,Allow
Deny From All
Allow 192.168.1.*
</Location>
# Allow access to the admin pages.
<Location /admin>
Encryption Required
Order Deny,Allow
Deny From All
Allow 192.168.1.*
</Location>
If you require encryption when accessing the admin pages there will be a very large delay when accessing them the first time, because the server must generate an SSL key. You can speed this up by increasing the entropy available to the random number generator by generating disk activity on the server. I did this with a simple find / command.
You can now connect to the cups server at <server>:631 and add the printer. Alternatively, you can add the printer from the command line on the server using lpadmin. You should now be able to print from the server; you can test from the web interface or with a command on the server like echo "Testing CUPS" | lpr. You should also be able to use the same procedure to add the printer to any Linux or OS X clients at this point.
Set up Samba
Next we must set up Samba to share the printer to the Windows machines on our network. You may not need Samba to do this, depending on your printer, but it lets you do some cool things we'll see later. My Samba setup is not the most secure since it was designed to serve my home network where I trust all the users. The following steps would need to be modified if deploying Samba in a less trusted environment.
Set the following options in /etc/samba/smb.conf
[global]
# Set this to the workgroup the windows machines belong to.
workgroup = WORKGROUP
# Allow access from the LAN only.
hosts allow 192.168.1.0/24
# The following removes the need to create accounts for each windows user
# on the samba server by mapping unknown users to the guest account. This
# is not particularly secure.
guest ok = yes
guest account = nobody
maptoguest = bad user
# Share the printer
load printers = yes
printing = cups
path = /var/spool/samba
browsable = yes
printable = yes
At this point you should be able to add the printer in Windows, although you might have to fight with drivers. In my case, HP drivers would not install if the printer was not connected to the computer's USB port. I believe this is an artifical limitation implemented by HP to prevent their "non-networked" printers from being networked. I could have run around to each windows computer on my LAN with the driver disk and the printer, but I found a better way; install the drivers over the network.
Push Drivers via Samba
A nice addition is to configure Samba to server printer drivers over the network, eliminating the need to manually install the drivers on each windows machine on the network. To do this, you need to download the CUPS Windows drivers, extract them, and run make install in the source directory.
Next, you will need to let Samba know about the drivers with the command:
# cupsaddsmb -H localhost -U root -a -v
This should be run on the Samba/CUPS server, and assumes you have created a Samba user named root.
Now add the following to your /etc/samba/smb.conf file:
[print$]
path = /usr/share/cups/drivers
browsable = yes
guest ok = yes
read only = yes
After restarting CUPS and Samba, you should be able to add the printer to a windows computer via the Add Printer Wizard and get the correct driver from the network via the Samba server.