Linux Interview Questions – Linux Printing (CUPS)

This post covers the most often asked how-to questions about Linux printing support.

What tool provides Linux printing support?

CUPS, the Common Unix Printing System

What kinds of printers can be attached to a Linux system?

Linux support printers which are connected using any of the following:

  • Locally Attached Printer (LPT) through a local parallel printer port.
  • Locally Attached Printer (USB) through a local USB port.
  • Remotely Attached Printer (IPP) using the Internet Printing Protocol (IPP).
  • Remotely Attached Printer (SMB-CIFS) through the Microsoft Windows SMB-CIFS protocol (Microsoft Windows Sharing).

All the necessary support is provided as part of the standard distribution.

What is CUPS?

The standard Linux printing services are provided by the Common Unix Printing System (CUPS). CUPS includes a web-based management interface that allows remote administration. Printers with similar capabilities may be grouped into pools for load sharing. CUPS is extensible, allowing additional drivers to support new printers.

CUPS is an open-source product released under the GNU General Public License (GPL) with some portions released under the GNU Library General Public License (LGPL). Full license information is available at the http://www.cups.org web site.

What Packages Do I Need To Install CUPS?

CUPS include as followed RPM packages:

  • cups: Common Unix Printing System
  • cups-libs: CUPS printing system – libraries.
  • hal-cups-utils: Halified CUPS utilities
  • libgnomecups: GNOME library for CUPS integration
  • gutenprint-cups: CUPS drivers for Canon, Epson, HP and compatible printers
  • foomatic: Database of printers and printer drivers

These packages are usually available on the installation of the Linux distribution. If you have repository configured, you can directly install these packages using yum or dnf commands.

How Is CUPS started?

CUPS is typically started at system boot time by init scripts.

Enable CUPS for future reboots by using the command:

# /sbin/chkconfig cups on

Start the CUPS service immediately for this boot by using the command:

# /sbin/service cups start

Verify that the CUPS service is running by using the command:

# /sbin/service cups status

How Is The CUPS Service Configured?

The default CUPS server configuration in /etc/cups/cupsd.conf is sufficient for most users. You may wish to modify it if you want to control remote access to your local printers.

CUPS provides an administrative interface available via a http://localhost:631 web interface. Click on the ADMINISTRATIVE tab. Most common customizations may be selected using the radio buttons listed. For less-common configuration changes, click the Edit Configuration File button to edit the configuration file directly; it is already heavily commented as a guide.

How Do I Add A Local Printer?

Choose any of the following methods:

  • The URL http://localhost:631 connects to the CUPS service. Click on the Add Printer button to start a wizard to add the printer.
  • From a GNOME session, click on the System/Administration/Printing path to invoke the system-config-printer utility. Click on the New Printer button and follow the wizard to complete the setup.
  • From the command line, use the lpadmin utility to add or configure the printer.

How Do I Add A Published, Remote CUPS Printer?

IPP Printers are printers that are attached to a different Linux system on the same network running CUPS or at least with IPP support configured. The networked IPP printers are found via CUPS browsing if the print server and client can send and receive connections on UDP port 631.

Listed below are the steps to configure the CUPS IPP client to see all the allowed networked IPP printer:

1. Make sure the desired hostname can be resolved using DNS. If you prefer using local /etc/hosts files, add the entry for the printer host to each networked computer:

127.0.0.1    localhost.localdomain localhost
10.0.0.2     example.thegeekdiary.com

Do not simply append a new host name to the 127.0.0.1 line or remote systems will not know to connect to your server.

2. Tell CUPS your server name. Modify the /etc/cups/clients.conf file and specify the “ServerName“:

ServerName example.thegeekdiary.com

Note: for CentOS/RHEL 6.x, the file name is “/etc/cups/client.conf

3. Restart the CUPS service for the changes to take effect:

# /sbin/service cups restart

Use any of the tools listed below to verify if the networked IPP printers are detected:

  1. system-config-printer
  2. redhat-config-printer
  3. printconf
  4. printtool
  5. printconf-gui

Once the printers are detected, they may be used immediately without further local configuration.

Which Printers Are Supported By CUPS?

To see which printers CUPS currently support, open the URL http://localhost:631 with a web browser. Click the Add Printer button to begin. Follow the prompts until the manufacturer and printer model selections are offered. If your printer is not listed, then you may close the browser window to abort adding the new printer.

Each CUPS-supported printer has a configuration file in the /usr/share/cups/model directory tree. These printer description files are text files, but may be hard to read. On RHEL/CentOS 5, the following shell script will display a list of the supported printers:

#!/bin/sh
find -L /usr/share/cups/model -type f -iname '*.ppd.gz' |
while read fn
do
case "${fn}" in
*.gz ) zcat ${fn};;
* ) cat ${fn};;
esac
done |
fgrep ModelName |
sed -e 's/^.[^"]*"//' -e 's/".*$//' |
sort -bdf

Save this script into the file supported-cups-printers and do this:

$ chmod +x supported-cups-printers
$ ./supported-cups-printers | head -n 5
Brother DCP-7025 BR-Script3
Brother DCP-8020 BR-Script3
Brother DCP-8025D BR-Script3
Brother DCP-8040 BR-Script3
Brother DCP-8045D BR-Script3

Alternatively, with command below to check the supported printers list:

# lpinfo --make-and-model {brand} -m ( while 'brand' can be hp,xerox,canon, etc )
# lpinfo --make-and-model canon -m | egrep S500
gutenprint.5.2://bjc-s500/expert Canon S500 - CUPS+Gutenprint v5.2.5
gutenprint.5.2://bjc-s500/simple Canon S500 - CUPS+Gutenprint v5.2.5 Simplified
foomatic:Canon-S500-bj8pa06n.upp.ppd Canon S500 Foomatic/bj8pa06n.upp

Where Can I Find More Print Drivers?

The http://linuxprinting.org web site is a good source for additional printer definition files. These files will have a “.ppd” filename extension. Once you have a definition file for your printer, just copy it to your local system. Start the system-config-printer utility from the command line or use the System/Administration/Printing desktop click path. Begin adding the printer. On the menu asking for the manufacturer and model, click the Provide PPD File radio button and give the path to your new PPD file.

Can I Use A Windows(tm) Printer Driver For My Unsupported Printer With CUPS?

Perhaps. You may have an executable file (EXE) that contains a PPD file inside it. Try this:

$ /usr/bin/unzip fooprint.exe

If the file unzips, there should be several directories with the Windows configuration files for the printer. Start looking in these directories for files ending with the “.ppd” extension. Then use that PPD file as described above.

Can My System Have A Default Printer?

Yes. You may select a default printer using any of these methods:

  • Open http://localhost:631 in a web browser. Click the Printers tab. Find your desired printer in the list and click its Set As Default button.
  • Run the system-config-printer utility, as described earlier. Highlight the desired printer in the list and click the Default button in the menu bar.
  • From the command line, use the lpadmin command:
# /usr/sbin/lpadmin -d [printername]

How Do I Migrate Print Settings From Another System?

The method used to migrate the print settings from one system to another depends on your preferred administration method.

For GUI based printer configuration utility (system-config-printer), use this technique:

1. Extract the settings on the old system. Prior to OEL4, use the redhat-config-printer-tui tool.

# /usr/sbin/system-config-printer-tui --Xexport > /tmp/settings.xml

2. Copy the /tmp/settings.xml file from the old system to the new system:

# /usr/bin/scp /tmp/settings.xml user@newsystem.foodomain.com:/tmp

3. Import the settings on the new system.

# /usr/sbin/system-config-printer-tui --Ximport 

4. Restart the print services on the new system with the following command:

# /sbin/service cups restart

Note: For CentOS/RHEL 5, the module /usr/sbin/system-config-printer-tui does not exist. Therefore xml files from other systems cannot be imported. It seems it is necessary to manually copy files below if the definitions are to be migrated from one system to another:

/etc/cups/ppd/*.ppd
/etc/cups/printers.conf
/etc/cups/classes.conf
/etc/cups/cupsd.conf

Restart the print services on the new system:

# /sbin/service cups restart

Check the new system to see if the printers are recognized, enabled, and printing properly. Simply start the GUI print configuration tool and look for the printers. Test by sending test pages.

Does CUPS Require SAMBA (SMB) Linux Support?

No. CUPS uses its own internet printing protocol (IPP) to communicate between clients and servers. The Linux SAMBA service is required only if the printer is hosted on a Windows(tm) system.

Related Post