Configuring Printers Using CUPS


You can use the Web interface or the command line interface to CUPS to manage printers and queues.

The CUPS Web Interface

CUPS, which was designed for Internet printing, provides a Web interface to configure printers. To connect to this interface, point a Web browser running on the local system at localhost:631.

Setting Up and Modifying a Printer

"JumpStart II: Configuring a Remote Printer Using CUPS" (page 508) discusses how to set up a remote printer using CUPS. The procedure for setting up a local printer is similar. The major difference is the second step: specifying the device that the printer is connected to.

A local printer is generally connected to USB Port #1 or Parallel Port #1. After you specify one of these devices, the Web interface displays the page on which you specify the brand of the printer; you do not specify a URI for a local printer. If you are setting up a serial printer, you will need to specify characteristics of the printer, including its baud rate. After these steps, the procedure is the same as explained in JumpStart II.

To modify a printer, first click Printers from the Web interface navigation bar and then click the Modify Printer button adjacent to the printer you want to modify. The Web interface takes you through the same steps as when you are setting up a new printer. If the Web interface does not allow you to modify a printer, click Administration instead of Printers on the navigation bar. Once you supply the username root and the root password, click Manage Printers and continue with the next paragraph.

Click the Stop Printer button to pause the printer. Click the Reject Jobs button to prevent jobs from being added to the printer's queue.

Jobs

Click Jobs on the navigation bar to display the Jobs page (Figure 14-9), which lists jobs in the print queues. From this page you can hold (pause), release (unpause), and cancel print jobs. Click Show Complete Jobs to display a list of recently completed jobs. In some cases, you can restart completed jobs from this page.

Figure 14-9. CUPS Web interface: Jobs page


Classes

CUPS allows you to put similar printers into a group called a class. A printer can belong to more than one class. A print job sent to a class will be printed on the first available printer in the class. For example, you may be able to divide your print jobs into black-and-white jobs and color jobs. If more than one printer can fulfill each of these roles, you can allow users to select a printer manually, or you can define two printer classes (black-and-white and color) and have users send their jobs to a certain class of printers.

Tip: Plan for the future

If you expect to add printers to the network, you may want to configure classes containing the existing printers when you set up the network. You can then add printers later without having to change printer configurations on client systems.


Adding printers to a class is a two-step process. First, you need to define a class. Second, you need to add existing printers to the class. To define a class, first click Classes on the navigation bar at the top of the page and then click Add Class. To clients, a class of printers appears as a single printer; for each class, you need to specify a name, location, and description. Once you have defined a class, you can add printers to the class. Repeat this process for each class you want to define.

CUPS on the Command Line

In addition to using the Web interface, you can control CUPS and manage print queues from the command line. This section details utilities that enable you to manage printers and print queues and establish printing quotas.

lpinfo: Displays Available Drivers

PPD files


The lpinfo utility provides information about the printer drivers and interfaces available to CUPS. The m option displays the list of available PostScript Printer Definition (PPD) files/drivers.

$ /usr/sbin/lpinfo -m | head raw Raw Queue foomatic-db-ppds/Brother/BR7025_2_GPL.ppd.gz Brother DCP-7025 BR-Script3 foomatic-db-ppds/Brother/BR8020_2_GPL.ppd.gz Brother DCP-8020 BR-Script3 foomatic-db-ppds/Brother/BR8025_2_GPL.ppd.gz Brother DCP-8025D BR-Script3 foomatic-db-ppds/Brother/BR8040_2_GPL.ppd.gz Brother DCP-8040 BR-Script3 foomatic-db-ppds/Brother/BR8045_2_GPL.ppd.gz Brother DCP-8045D BR-Script3 foomatic-db-ppds/Brother/BRHL14_1_GPL.ppd.gz Brother HL-1450 BR-Script2 foomatic-db-ppds/Brother/BRHL14_2_GPL.ppd.gz Brother HL-1470N BR-Script2 foomatic-db-ppds/Brother/BRHL16_2_GPL.ppd.gz Brother HL-1650/70N BR-Script3 foomatic-db-ppds/Brother/BRHL18_2_GPL.ppd.gz Brother HL-1850/70N BR-Script3


CUPS uses URIs (page 1061) to identify printer ports by type and location, just as a Web browser identifies documents by protocol and location. A parallel port has a URI with the format parallel:/dev/lp0; a remote LPD printer uses the format lpd://192.168.0.101. With the v option, lpinfo provides a list of available connections:

$ /usr/sbin/lpinfo -v network socket network beh direct hal direct hp:/no_device_found network http network ipp network lpd direct parallel:/dev/lp0 direct scsi serial serial:/dev/ttyS0?baud=115200 ... direct usb:/dev/usb/lp0 direct usb:/dev/usb/lp1 ... network smb


The v option to lpinfo does not display every possible network address for the socket, HTTP, IPP, LPD, and SMB protocols because there are more than 4 billion of these addresses in the IPv4 address space.

lpadmin: Configures Printers

The lpadmin utility can add and remove printers from the system, modify printer configurations, and manage printer classes. It has three major options: d (set the default printer), x (remove a printer), and p (add or modify a printer). The first two options are simple; examples are shown after the next section. Each of the options takes an argument that is the name of a printer. The name of the printer must start with a letter and cannot contain SPACEs.

Adding or Modifying a Printer

You add a printer or modify an existing printer by giving a command in the following format:

# /usr/sbin/lpadmin p printer options


Here printer is the name of the printer and options is a combination of options from the following list:

c class


Adds the printer to the class class, creating the class if necessary.

D info


The info is a string that describes the printer for users. This string has no meaning to the system. Enclose info within quotation marks if it contains SPACEs.

E


Enables the printer and instructs CUPS to accept jobs into its print queue.

L loc


The loc is a string that physically locates the printer for users (office, building, floor, and so on). This string has no meaning to the system. Enclose loc within quotation marks if it contains SPACEs.

m model


The model is the name of the PPD file (page 514) that describes the printer. Use lpinfo m to display a list of all of the installed PPD files. If you have a manufacturer-provided PPD file, copy it to /usr/share/cups/model. Use the P option to specify the pathname of the file. Specifying m postscript.ppd.gz, for example, is the same as specifying P /usr/share/cups/model/postscript.ppd.gz.

P file


The file is the absolute pathname of the PPD file (page 514) that holds the printer driver. See m for an alternative way to specify a PPD file.

r class


Removes the printer from the class class. This option removes the class if, after removing the printer, the class would be left empty.

v URI


The URI is the device to which the printer is attached. Use lpinfo v to list possible devices.

Example lpadmin Commands

At a minimum, you need to provide a device and a model when you add a printer to the system. The following command adds an Epson Stylus Color printer to the system and enables it for use. The printer is connected locally to the first parallel port and is named ColorPrinter.

# lpadmin -p ColorPrinter -E -v parallel:/dev/lp0 -m stcolor.ppd.gz


The printer information generated by the preceding command is stored in the /etc/cups/printers.conf file.

# cat /etc/cups/printers.conf # Printer configuration file for CUPS v1.1.23 # Written by cupsd on Fri 27 Jan 2006 05:00:32 PM PST <Printer ColorPrinter> Info ColorPrinter DeviceURI parallel:/dev/lp0 State Idle Accepting Yes JobSheets none none QuotaPeriod 0 PageLimit 0 KLimit 0 Autodetected No </Printer>


The printer driver information from the /usr/share/cups/model/stcolor.ppd.gz file is uncompressed and copied to /etc/cups/ppd. The resulting file is given the printer's name: /etc/cups/ppd/ColorPrinter.ppd.

You can modify a printer configuration with lpadmin using the same options that you used to add it. When you specify the name of an existing printer, lpadmin modifies the printer rather than creating a new one.

The next command configures an HP LaserJet-compatible printer with a JetDirect interface that is connected directly to the LAN at 192.168.1.103 and names this printer HPLJ. Specifying socket in the protocol part of the URI instructs CUPS to use the JetDirect protocol, a proprietary protocol developed by HP for printers connected directly to a network.

# lpadmin -p HPLJ -E -v socket://192.168.1.103 -m laserjet.ppd.gz


The lpstat utility with the d option displays the name of the default printer:

$ lpstat -d system default destination: MainPrinter


CUPS automatically makes the first printer you defined the default printer. The following command makes HPLJ the default printer:

# lpadmin -d HPLJ


The following command removes the configuration for the ColorPrinter printer:

# lpadmin -x ColorPrinter


Printing Quotas

CUPS provides rudimentary printing quotas. You can define two forms of quotas: page count and file size. File size quotas are almost meaningless because a small PostScript file can take a long time to interpret and can require a lot more ink to print than a large one. Page quotas are more useful, although their implementation is flawed. To determine the number of pages in a document, CUPS examines the PostScript input. If a job is submitted in the printer's native language, such as PCL, CUPS bypasses this accounting mechanism. Also, if mpage is used to create a PostScript file with multiple pages printed on each sheet, CUPS counts each page in the original document, rather than each sheet of paper it prints on.

Use the job-quota-period and either job-page-limit or job-k-limit to establish a quota for each user on a given printer. The job-quota-period option specifies the number of seconds that the quota remains valid. The following command establishes a quota of 20 pages per day per user for the printer named HPLJ:

$ lpadmin -p HPLJ -o job-quota-period=86400 -o job-page-limit=20


The job-k-limit option works similarly but defines a file size limit in kilobytes. The limit is the total number of kilobytes that each user can print over the quota period. Once a user has exceeded her quota, she will not be allowed to print until the next quota period.

Managing Print Queues

When a printer is operating normally, it accepts jobs into its print queue and prints them in the order they are received. Two factors determine how a printer handles a job: if the printer is accepting jobs and if it is enabled. Table 14-2 shows what happens in each of the four combinations of the two factors.

Table 14-2. Printer status
 

Enabled

Disabled

Accepting Jobs

Accepts new jobs into the queue.

Prints jobs from the queue.

Accepts new jobs into the queue.

Does not print jobs from the queue until the printer is enabled.

Rejecting Jobs

Rejects new jobs.

Prints jobs from the queue.

Rejects new jobs.

Does not print jobs from the queue until the printer is enabled.


The utilities that change these factors are disable, enable, reject, and accept. Each utility takes the name of a printer as an argument. The following commands first disable and then enable the printer named HPLJ:

# /usr/bin/disable HPLJ # /usr/bin/enable HPLJ


The next commands cause HPLJ to reject and then accept jobs:

# /usr/sbin/reject HPLJ # /usr/sbin/accept HPLJ


The enable and disable utilities are located in /usr/bin, while reject and accept are located in /usr/sbin. Depending on how the PATH environment variable (page 292) is set, you may need to specify absolute pathnames for disable, reject, and accept. Because enable is a bash builtin (page 225), you always need to specify the absolute pathname of this utility. You may want to create aliases (page 318) for these commands to make them easier to use.

Sharing CUPS Printers

IPP is designed for remote printing. By default, CUPS binds to localhost and accepts connections from the local system only. To allow other systems to connect to CUPS on the local system, you must instruct CUPS to bind to an IP address that the other computers can reach. The Listen directive in the CUPS configuration file, /etc/cups/cupsd.conf, specifies which IP address CUPS binds to and accepts requests on. The Listen directive has the following format:

Listen IP:port


where IP is the IP address that CUPS accepts connections on and port is the port number that CUPS listens on for connections on IP. CUPS typically uses port 631. For example, the following directive causes CUPS to listen on IP address 192.168.0.10, port 631:

Listen 192.168.0.10:631


After you change cupsd.conf, you need to restart the CUPS daemon:

# /sbin/service cups restart Stopping cups:                                                      [  OK  ] Starting cups:                                                      [  OK  ]


Once you restart the CUPS daemon, remote systems can print on the local system's printers using the IP address and port number specified with the Listen directive. Make sure the system's firewall (page 768) allows LAN users to connect to port 631 on the local system and does not allow systems outside the LAN to connect to this port. You may also need to modify the SELinux policy (page 402) depending on the system setup.

Alternatively, you can use CUPS's access control list to permit only selected machines to connect to local printers. An access control list is defined inside a <Location> container. The following example allows only the system at IP 192.168.1.101 and the local system to print to the specified printer:

<Location /printers> Order Deny,Allow Allow from 192.168.1.101 Allow from @LOCAL </Location>


The /printers indicates that this container refers to all local printers. Alternatively, you can control access on a per-printer basis by specifying /printers/name, where name is the printer name, or by specifying /printers/path.ppd, where path.ppd is the full pathname of the PPD file (page 514) used by the printer.

The Order Deny, Allow line denies print requests by default and allows requests only from specified addresses. Specifying Order Allow, Deny allows print requests by default and denies requests from specified addresses.

Allow from specifies the IP addresses that CUPS accepts connections from. Use Deny from with Order Allow, Deny to specify IP addresses that CUPS will not accept connections from.

The @LOCAL macro specifies the local system: It accept jobs from any address that resolves to the local system. Specifying 127.0.0.1 in place of @LOCAL would work as long as no application tried to print to the print server using its external IP address. Do not use the machine's external IP address. Most processes use the loop-back device (127.0.0.1) to connect to the printer, and the loopback device does not allow connections to any IP other than itself. You can also use domain names, including wildcards, and IP ranges with either wildcards or netmasks in Allow from and Deny from directives.




A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net