Pages

Network Printer Configuration on Linux via Command Line

CUPS (formerly Common Unix Printing System) provides print server capabilities to Unix like Operating Systems. There are basically two components of CPUS: print spooler (or simultaneous peripheral output on line) and scheduler. CUPS is based on standard network protocol Internet Printing Protocol (IPP) for managing print jobs and queues. Most of the Linux distributions use CUPS as their default printing system including Red Hat starting with Red Hat Linux 9. Today we will complete network printer configuration on Red Hat Enterprise Linux 5 via command line using CUPS.

Let's check if CUPS daemon is running,

# /etc/init.d/cups status

If not then go ahead and start the CUPS daemon and also set to start at boot time,

# /etc/init.d/cups start
# chkconfig cups on

lpadmin is a very powerful tool to configure printers provided by CUPS. Let's use it,

# lpadmin -p <printer name> -E -v socket://<printer ip address>

In the above command,
    -E option enables the printer and accepts jobs
    -p option set the printer DNS name
    -v option set the printer URI but I prefer printer IP address

We can also set default printer using lpadmin command,

# lpadmin -d <printer name>

lpadmin program can also be used to delete the printer destination but that will also remove all pending jobs for the destination and abort the running jobs.

# lpadmin -x <printer name>

Network printer configuration on Red Hat Enterprise Linux 5 has been successfully completed now. But there are few validation steps that you we can do to make sure things are working as expected.

Check CUPS status information and see if your printer shows enabled there,

# lpstat -p

Check printer queue status and see if your printer is in ready mode,

# lpq

If the printer is not set to default printer then use,

# lpq -P <printer name>

Print a test page,

# lpr /usr/share/cups/data/testprint.ps

If the printer is not set to default printer then use,

# lpr -P <printer name> /usr/share/cups/data/testprint.ps

We have successfully completed the validation steps for network printer configuration here but if you want to use your own or vendor provided PPD file for printer configuration then below steps are for you.

CUPS provide most of the major drivers and you can list the available drivers by command,

# lpinfo -m

Under RHEL5, all the PPDs (PostScript Printer Description) are stored at following location,

# /usr/share/cups/model

But if you have your own PPD file then you can gzip the file and put it under,

# /usr/share/cups/model

Make sure to restart the CUPS daemon,

# service cups restart

Now use below command,

# lpadmin -p {printer name} -E -v socket://{printer ip address} -P {filename}.ppd.gz

Any feedback will be highly appreciated.

Suggested Posts,

This post appeared on the softlexicon.com by Sumit Goel. Copyright © 2012–2013 – softlexicon.com and Sumit Goel. All rights reserved. Not to be reproduced for commercial purposes without written permission.

24 comments:

  1. Hi
    Wat abt the print drivers to pick?

    ReplyDelete
  2. Hi Mahesh,

    CUPS provide most of the major drivers and you can list the available drivers by command,

    # lpinfo -m

    Under RHEL5, all the PPDs (PostScript Printer Description) are stored at following location,

    # /usr/share/cups/model

    But if you have your own PPD file then you can gzip the file and put it under,

    # /usr/share/cups/model

    Make sure to restart the CUPS daemon,

    # service cups restart

    Now use below command,

    # lpadmin -p {printer name} -E -v socket://{printer ip address} -P {filename}.ppd.gz

    Let me know if that answers your question.

    ReplyDelete
  3. I am unable to search newly added network printer which need to configured on CUPS using GUI. Can we search new network printer using command line?

    ReplyDelete
  4. Thanks, this was exactly what I was looking for.

    ReplyDelete
  5. lpr: Error - unable to access - No such file or directory
    Why is this happening

    ReplyDelete
  6. this is when I go to print a test page not on a default printer.

    ReplyDelete
    Replies
    1. Kenedi, what Linux distribution you are trying it on?

      Delete
  7. This is exactly what I was looking for, thanks for the article Sumit!

    ReplyDelete
  8. Thank you, very useful indeed for a Linux/CUPS newb like myself.. :)

    ReplyDelete
  9. I tried CUPS with above document. Bt i got the message as follwing
    Rank Owner Job File(s) Total Size
    active root 37 testprint 1024 bytes
    1st root 38 testprint 1024 bytes
    2nd root 39 testprint 1024 bytes

    But i canot able to print.. Anyone can help me?

    ReplyDelete
  10. I am getting below message ..

    printer is on device 'socket' speed -1
    queuing is enabled
    printing is disabled
    1 entries
    daemon present

    is it something that we need to enable printing first

    ReplyDelete
    Replies
    1. Enable the printing for the printer :

      cupsenable

      Delete
  11. Thanks buddy, nice article. It's helpful.

    ReplyDelete
  12. lpadmin: Unable to connect to server: No such file or directory

    ReplyDelete
  13. Sibling Printers have widely known as a well set up name in the printer business. With numerous honors and acclaim that it has got, Brother is certainly a remarkable name in the best printer brands out in the business sector today. https://800support.net/printer-support/hp-printer-support/

    ReplyDelete

Be sure to check back again because I do make every effort to reply to your comments here.