Redhat Link: How to setup printers from the command line using lpadmin in RHEL

Environment

  • Red Hat Enterprise Linux (RHEL), all versions
  • Common Unix Printing System (CUPS)

Issue

  • How to setup printer from the command line using lpadmin whose drivers are provided in Red Hat Enterprise Linux.
  • We need the command syntax to add a print queue that will point to a serial device.
  • How do I add printer(s) to my Common UNIX Printing System (CUPS) print server without using any of the GUI tools?
  • We have hundreds of CUPS printers currently defined, but are a mix of socket/LPD, printer name/IP, different drivers. We’re wanting to standardize our environment and need to change/set the following attributes at the command line if at all possible (I’ll be scripting it).

Resolution

If you already have a PostScript Printer Definition (PPD) file for the printer that you would like to install, skip to step 3.

  1. Install the latest foomatic and hplip packages from the RHEL channel:

    yum -y install foomatic hplip
    
  2. Use the lpinfo command to list supported printers:

    lpinfo -m 
    

    For example, to list the PPD files available for the “Ricoh Aficio MP 2000” use something like:

    # lpinfo -m | grep -i 'aficio.*2000'
    foomatic-db-ppds/Ricoh/PS/Ricoh-Aficio_CL2000_PS.ppd.gz Ricoh Aficio CL2000 PS
    foomatic-db-ppds/Ricoh/PS/Ricoh-Aficio_MP_2000_PS.ppd.gz Ricoh Aficio MP 2000 PS
    foomatic-db-ppds/Ricoh/PXL/Ricoh-Aficio_MP_2000_PXL.ppd.gz Ricoh Aficio MP 2000 PXL
    
  3. Use the lpinfo command to list available print devices. For example:

    # lpinfo -v
    network socket
    network https
    network ipps
    network ipp
    network http
    network lpd
    direct hp
    serial serial:/dev/ttyS0?baud=115200
    network beh
    direct hpfax
    network smb
    
  4. Put it all together with the lpadmin command to install the print queue:

    lpadmin -p <print-queue-name> -m <model-from-lpinfo> -v <device-uri> -E
    

    or, if you have a PPD file from the printer vendor or a non-Red Hat source, use:

    lpadmin -p <print-queue-name> -P </path/to/ppd/file> -v <device-uri> -E
    

    where:

    • -p <print-queue-name> is the name of the print queue you want to define
    • -m <model-from-lpinfo> is the model information that was returned by the lpinfo -m command
    • -P </path/to/ppd/file> is the PPD file that you have for the printer
    • -v <device-uri> is a valid device URI constructed from the information returned by the lpinfo -v command.
    • -E enables the printer.

    For example, to install the “Ricoh Aficio MP 2000” printer mentioned previously (assuming that it has an IP address of 10.1.2.3 and you want to call the queue rmP2000):

    lpadmin -p rmp2000 -m foomatic-db-ppds/Ricoh/PS/Ricoh-Aficio_MP_2000_PS.ppd.gz -v socket://10.1.2.3/ -E
    

Additional Information

Additional information on determine if your printer is supported in RHEL can be found in:

What printers and print drivers are supported for use with CUPS in RHEL?

Additional information on obtaining and using PPD files can be found in:

How to install a new PostScript Printer Definition (PPD) file.

Examples

  • Network – JetDirect/AppSocket

    # lpinfo -m | grep Ricoh | grep CL2000
    foomatic-db-ppds/Ricoh/PS/Ricoh-Aficio_CL2000_PS.ppd.gz Ricoh Aficio CL2000 PS
    
    # lpadmin -p 5th-floor-mfp -v socket://10.1.2.3:9100 -m foomatic-db-ppds/Ricoh/PS/Ricoh-Aficio_CL2000_PS.ppd.gz -E
    
  • Network – LPD

    # lpinfo -m | grep Canon | grep imageRunner | grep 'C6800'
    foomatic:Canon-imageRunner_C6800-hpijs-pcl5c.ppd Canon imageRunner C6800 Foomatic/hpijs-pcl5c
    foomatic:Canon-imageRunner_C6800-Postscript.ppd Canon imageRunner C6800 Foomatic/Postscript
    
    # lpadmin -p canon-west -v lpd://10.1.2.3/PASSTHRU -m foomatic:Canon-imageRunner_C6800-hpijs-pcl5c.ppd -E
    

    More information on printing to LPD printers can be found in Configure RHEL to print to Unix print servers.

  • USB

    # lpinfo -m | grep Epson | grep Photo
    drv:///sample.drv/stphoto2.ppd Epson New Stylus Photo Series
    foomatic:Epson-Stylus_Photo_750-stcolor.ppd Epson Stylus Photo 750 Foomatic/stcolor
    drv:///sample.drv/stphoto.ppd Epson Stylus Photo Series
    
    # lpadmin -p local-epson-photo -E -v usb:/dev/usb/lp0 -m drv:///sample.drv/stphoto2.ppd
    
  • Serial

    # lpinfo -v | grep serial
    serial serial:/dev/ttyS0?baud=115200
    
    # lpinfo -m | grep Epson | grep Dot
    foomatic:Epson-Dot_Matrix-eps9high.ppd Epson Dot Matrix Foomatic/eps9high
    foomatic:Epson-Dot_Matrix-eps9mid.ppd Epson Dot Matrix Foomatic/eps9mid
    foomatic:Epson-Dot_Matrix-epson.ppd Epson Dot Matrix Foomatic/epson
    foomatic:Epson-Dot_Matrix-epsonc.ppd Epson Dot Matrix Foomatic/epsonc
    
    # lpadmin -p local-dot-matrix -E -v serial:/dev/ttyS0?baud=115200 -m foomatic:Epson-Dot_Matrix-epson.ppd
    
  • Parallel

    # lpinfo -m | grep Epson | grep Photo
      drv:///sample.drv/stphoto2.ppd Epson New Stylus Photo Series
      foomatic:Epson-Stylus_Photo_750-stcolor.ppd Epson Stylus Photo 750 Foomatic/stcolor
      drv:///sample.drv/stphoto.ppd Epson Stylus Photo Series
    
    # lpadmin -p local-epson-photo -E -v usb:/dev/usb/lp0 -m foomatic:Epson-Stylus_Photo_750-stcolor.ppd
    
  • Windows (additional information for setting up Windows printers can be found in How to configure CUPS to print to a Windows print server)

    # lpinfo -m | grep HP | grep LaserJet | grep 8150
      foomatic:HP-LaserJet_8150-lj4dith.ppd HP LaserJet 8150 Foomatic/lj4dith
      foomatic:HP-LaserJet_8150-lj5gray.ppd HP LaserJet 8150 Foomatic/lj5gray
      foomatic:HP-LaserJet_8150-ljet4.ppd HP LaserJet 8150 Foomatic/ljet4
      foomatic:HP-LaserJet_8150-Postscript.ppd HP LaserJet 8150 Foomatic/Postscript
      foomatic:HP-LaserJet_8150-pxlmono.ppd HP LaserJet 8150 Foomatic/pxlmono
    
    # lpadmin -p winprinter -E -v smb://username:password@10.1.2.3/HP -m foomatic:HP-LaserJet_8150-Postscript.pp