Thursday, November 27, 2008

Sharing Linux Printers Across Multiple Subnets

Sharing Linux Printers Across Multiple Subnets

1)Configuring CUPS For Two Subnets



All you need to make this work are a central Linux/CUPS printer server, and one Linux PC per subnet to act as a relay printer server.

Let's say you have two subnets, 192.168.1.0/24 and 192.168.2.0/24. You need to have routing already configured to pass traffic between the two subnets, so everyone can ping everyone. Let's say you have your CUPS printer server at 192.168.1.10, and you want computers on 192.168.2.0/24 to be able to use it. This is a complete, barebones example CUPS configuration for 192.168.1.10:

##/etc/cups/cupsd.conf
LogLevel warning

#this varies; check your distribution
SystemGroup lpadmin

# Allow remote users to access this server
Port 631
Listen /var/run/cups/cups.sock

# Enable printer sharing
Browsing On
BrowseAllow all
BrowseAddress 192.168.1.255
BrowseAddress 192.168.2.255
DefaultAuthType Basic


# Allow shared printing
Order allow,deny
Allow 192.168.1.0/24
Allow 192.168.2.0/24



# Only local users can access Web admin pages
Order allow,deny
Allow localhost



# Only local system users can access config files
AuthType Basic
Require user @SYSTEM
Order allow,deny
Allow localhost

You may use hostnames in place of IP addresses. Then restart CUPS, either /etc/init.d/cupsys restart on Debian-ish systems, or /etc/init.d/cup restart on Fedora/Red Hat-ish systems.

Setting Up the Relay PC

Pick one computer in the 192.168.2.0/24 network to act as your "relay" server; it will contact the printer server and then relay its printers to the rest of the 192.168.2.0/24 subnet. Just add these lines to cupsd.conf:

BrowsePoll 192.168.1.10
BrowseRelay 127.0.0.1 192.168.2.255



# Allow shared printing
Order allow,deny
Allow 192.168.2.0/24

Restart CUPS, and in half a minute or so all the computers on 192.168.2.0/24 should see all the printers that are physically attached to the server at 192.168.1.10. What if you have more than one printer server to share? Then add a line for each server like this:

BrowsePoll 192.168.1.10
BrowsePoll 192.168.1.15
BrowsePoll 192.168.1.20
BrowseRelay 127.0.0.1 192.168.2.255

This is nice and efficient because all you need is one PC per subnet to act as the relay.

You can easily test all of this from the comfort of your secret armored underground network administrator lair, because of course you have OpenSSH set up all over your network so that you can securely log in to all hosts and do stuff. First log into your relay computer, then use lpstat to see what printers are available:

$ lpstat -v
device for HP_LaserJet_3050: ipp://uberpc.alrac.net:631/printers/HP_LaserJet_3050
device for HP_LaserJet_6L_LPT_parport0_HPLIP: ipp://xena.alrac.net:631/
printers/HP_LaserJet_6L_LPT_parport0_HPLIP
device for tp0: ipp://uberpc.alrac.net:631/printers/tp0
Now that is a happy sight; you can see printers from two different printer servers. You can see if they are ready to use:
$ lpstat -a HP_LaserJet_3050
HP_LaserJet_3050 accepting requests since Tue 18 Dec 2007 07:07:39 PM PST

You can even print a test page remotely:

$ lpr -P HP_LaserJet_3050 /etc/cups/cupsd.conf

CUPS relies on polling to notify the entire network about what printers are up. By default each CUPS server send out an 80-byte broadcast packet every thirty seconds. If this gets to be too much, or if your printer setup doesn't change very often, you can change this behavior:

BrowseInterval  360
BrowseTimeout 600
This polls the network every six minutes, and if any CUPS server does not respond within ten minutes it is removed from the browse list.

If you want to also serve Windows clients, simply set up a Samba printer share in the usual way, and use Samba's own access controls to cross subnets.

So there you are- as easy as falling over and a lot more fun

No comments: