LFCS - Printing Setup and Management with CUPS

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
344
Reaction score
377
Credits
11,920
Network printing allows for the sharing of printers. By sharing printers, you can reduce the number of required resources needed to be purchased.

Systems send print jobs to the print server. The print server will hold a job in the print queue until the printer can accept the print job. Jobs in the queue can stay in the queue, even after being printed, so you can print the job again and not need to be printed from the client system.

Install and Configure CUPS

The Common UNIX Printing System (CUPS) is used to create job queues for every network printer.

To install the CUPS and perform configuration, it is best to have elevated rights, so execute the command 'sudo su'. Enter the password, if asked, and you should be at an elevated user prompt, noted by the '#'.

To install the CUPS service, use the command 'yum install cups -y' on CentOS. For Ubuntu, use 'apt install cups -y', if it isn't present already.

Once you install the service, we need to start the service and enable it to auto-start when the system boots up. Run the commands:

systemctl start cups
systemctl enable cups


Currently, the service is only listening to Port 631 for 'localhost'. To change this, we need to add our network port for our local network, which in my case is '192.168.32.101'. Use your IP Address of the CUPS Server instead of mine. If you are following along using your VirtualBox machines, add CUPS to Server1.

Edit the file '/etc/cups/cupsd.conf'.

NOTE: The file is in the same location for Ubuntu, but the lines are in different places for items that need added.

At the top, add a line after 'MaxLogSize 0' and type in 'DefaultEncryption Never'. The line allows the system to not require an SSL certificate to access the Web Interface.

Move down a few lines to the one that is 'Listen localhost:631' and add a line after it. Add 'Listen 192.168.32.101:631' to the blank line.

Move down a few lines again to the line '<Location />' and just below it is the line 'Order allow,deny'. After this second line, add two blank lines. On the first one, add 'allow localhost:631'. On the second line, add 'allow 192.168.32.0/24'. These are the networks that may access the server. Just down a line is '<Locate /admin>'. Add the same two lines in the same way as previously.

Save the file and exit the editor.

Since we change the configuration file, we need to make the settings take effect. Perform the following:

systemctl restart cups
netstat -lnt


The 'netstat' command should show that the localhost and network port are listening to Port 631. Everything is nearly ready except that the firewall blocks the Port on CentOS. The port is open on Ubuntu so you do not need the next two commands. Execute the command to open the CentOS port:

ufw allow 631/tcp
ufw reload


From another system on the network you specified in the configuration file, you can open a browser and enter 'http://192.168.32.101:631', which would give you a screen like Figure 1.

Figure 1.JPG

FIGURE 1

NOTE:
I installed a graphical interface on Server2 to have the Graphical User Interface (GUI) to use a browser to perform this step.

If you do not see the screen, make sure you followed all the directions. Make sure both systems can ping each other using the IP Address network used in the configuration file.

NOTE: For CentOS systems, you need to run a command on Server1 to add your user to the 'sys' group so you can add printers. Use the command 'sudo usermod -a -G sys <username>'.

Web Interface Management

Now that the Web Interface is working, we can look at managing the Print Server from a browser. This is the easiest way to manage the service. The system shows the version of the CUPS Service on the web page.

NOTE: The Ubuntu version of CUPS is higher than that on CentOS, but the management interface is still nearly the same. The differences are purely aesthetic.

To add a printer, just open the 'Administration' tab, which is shown in Figure 2 on Ubuntu. Click on 'Add Printer' to add a new printer to the server to manage.

Figure 2.JPG

FIGURE 2

It may prompt you for a Username and Password to continue.

The next screen, Figure 3, lets you choose a local printer or a network printer, if the system detects the network printer. In my example, I will choose to add an HP Printer (HPLIP) . After clicking 'Next', it will ask me to enter the connection, Figure 4. To continue the example, I will enter 'http://192.168.32.101:631/ipp/port1'. Once you enter a connection, click 'Next'.

Figure 3.JPG

FIGURE 3

Figure 4.JPG

FIGURE 4

Next, it prompts you to enter information about the printer, as shown in Figure 5. You can enter the Name, Description and Location. There is also a box to be checked to share the printer. If other systems are to print to the printer, you will need to share the printer. If the printer is only for use by the local system, do not share it.

Figure 5.JPG

FIGURE 5

The printer's name cannot contain spaces or slashes. Click 'Continue' to go on.

In Figure 6, the next screen, you will choose the Make of the printer. After choosing a Make, it will prompt you for the Model, in Figure 7.

Figure 6.JPG

FIGURE 6

Figure 7.JPG

FIGURE 7

For the Make, I will choose an 'HP Officejet 6100'.

After clicking on 'Add Printer', it will then prompt you to set the default properties for the printer. In Figure 8, there are multiple tabs to set defaults on.

Figure 8.JPG

FIGURE 8

Make all the changes you need to and click on 'Set Default Options'. We should then add the printer to the Print Server to be managed.

For Ubuntu, I added the printer to my client, in this case Server2, with the command 'sudo lpadmin -p HP-Printer -E -v http://192.168.32.101:631/ipp/port1'. I kept getting errors when trying to add it from the GUI in the 'Printers' settings.

On Server1, I can print a document or something and a job should appear in the Job Queue. For CentOS, you can print a document from the Command-Line Interface (CLI) using the command 'lpr -P HP-Printer /etc/hosts'. The name after the parameter '-P' is the Printer Name. The file at the end of the command, '/etc/hosts', is the file to print. Again, it should show up in the Job Queue viewed from the Web Interface.

Look around the Web Interface to get an idea of what you can do from within the browser.

Command-Line Interface Management

Sometimes, you may have a system that has no GUI. So, you need to be aware of how to manage the printer from the CLI.

To see a full list of the installed printer drivers, use the command 'lpinfo -m' and you should see something similar to Figure 9.

Figure 9.JPG

FIGURE 9

Your printer manufacturer should hopefully supply a Linux driver which is a 'ppd' file. Let's assume our printer is listed here, in Figure 9, and is the HP Laserjet 4P, which uses PCL 5. The driver for the printer is the built-in 'drv:///sample.drv//laserjet.ppd'.

If we want to add the printer, in this case it is a dummy printer that will have a queue. The print jobs will sit in the queue and not go to the printer, but this works fine for demonstration.

To add the printer, we need the driver's name, which we have, and a share name. We also need a connection type.

The command to add the printer is 'lpadmin -p HP2 -E -v ipp://192.168.32.150/ipp/print -m drv:///sample.drv/laserjet.ppd'. The printer name is 'HP2', it enables the printer (-E), and points to a network printer at address '192.168.32.150', with the driver we covered previously.

Once you add a printer, you can specify the default printer by using the command 'lpadmin -d <printer-name>'. In the example, the command we would issue would be 'lpadmin -d HP2'. To check the default printer, use the command 'lpstat -d'.

To make sure a printer is accepting print jobs, you can issue the command 'cupsaccept <printer-name>'. The example would be 'cupsaccept HP2'.

You can see the status of all printers with the command 'lpc status'. If a device shows ‘disabled’, then you can run the command 'cupsenable <printer-name>'. We can disable a printer with the command 'cupsdisable <printer-name>'.

If you want to see the queue of a printer, use the command 'lpq'. The command will display the queue of the default printer. Should you want to see the queue of a different printer, you need to specify it after the '-P' parameter'. For example, to check the 'HP-Printer' device, the command is: 'lpq -P HP-Printer'.

Once you view a queue, each job in the queue has a job number. You can delete the job, active or not, by using the command 'lprm #'. Just specify the job number to remove from the queue. You can delete all jobs by using the command 'cancel -ax'. Here, it deletes all jobs on the default printer. If you want to delete all jobs on 'HP-Printer', use the command 'cancel -ax HP-Printer'.

You can delete a printer with the command 'lpadmin -x <printer-name>'.

Conclusion

Printing is an essential part of computing. Being able to install and manage network printers is a necessity.

Practice these techniques from the command line and the web interface. All of this can be very handy.
 


Thank you very much, Jarret. Very informative and nicely written article.
 
Thank you for the info, Jarret. However, I am a noob at editing in the command line and text editors. Right now, I am stuck
editing the file '/etc/cups/cupsd.conf'. Is that editing in the terminal or text editor? And how do I get access to the file?

System:
Kernel: 6.1.0-15-amd64 arch: x86_64 bits: 64 compiler: gcc v: 12.2.0 Desktop: Cinnamon v: 5.8.4
tk: GTK v: 3.24.38 wm: muffin dm: LightDM Distro: LMDE 6 Faye base: Debian 12.1 bookworm
Machine:
Type: Desktop System: ASUS product: N/A v: N/A serial: <superuser required>
Mobo: ASUSTeK model: TUF GAMING B550M-PLUS (WI-FI) v: Rev X.0x serial: <superuser required>
UEFI: American Megatrends v: 1202 date: 10/22/2020
CPU:
Info: 8-core model: AMD Ryzen 7 5800X bits: 64 type: MT MCP arch: Zen 3+ rev: 0 cache:
L1: 512 KiB L2: 4 MiB L3: 32 MiB
Speed (MHz): avg: 2457 high: 3800 min/max: 2200/4850 boost: enabled cores: 1: 2051 2: 2200
3: 2200 4: 3800 5: 3800 6: 2200 7: 2052 8: 2070 9: 2200 10: 3800 11: 2048 12: 2200 13: 2200
14: 2200 15: 2200 16: 2095 bogomips: 121374
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
Graphics:
Device-1: AMD Navi 22 [Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT] vendor: Gigabyte
driver: amdgpu v: kernel arch: RDNA-2 pcie: speed: 16 GT/s lanes: 16 ports: active: HDMI-A-2
empty: DP-1,DP-2,HDMI-A-1 bus-ID: 0a:00.0 chip-ID: 1002:73df
Display: x11 server: X.Org v: 1.21.1.7 with: Xwayland v: 22.1.9 driver: X: loaded: amdgpu
unloaded: fbdev,modesetting,radeon,vesa dri: radeonsi gpu: amdgpu display-ID: :0 screens: 1
Screen-1: 0 s-res: 3840x2160 s-dpi: 96
Monitor-1: HDMI-A-2 mapped: HDMI-A-1 model: INSIGNIA-TV res: 3840x2160 dpi: 138
diag: 1079mm (42.5")
API: OpenGL v: 4.6 Mesa 22.3.6 renderer: AMD Radeon RX 6750 XT (navi22 LLVM 15.0.6 DRM 3.49
6.1.0-15-amd64) direct-render: Yes
Audio:
Device-1: AMD Navi 21/23 HDMI/DP Audio driver: snd_hda_intel v: kernel pcie: speed: 16 GT/s
lanes: 16 bus-ID: 0a:00.1 chip-ID: 1002:ab28
Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK driver: snd_hda_intel v: kernel pcie:
speed: 16 GT/s lanes: 16 bus-ID: 0c:00.4 chip-ID: 1022:1487
API: ALSA v: k6.1.0-15-amd64 status: kernel-api
Server-1: JACK v: 1.9.21 status: off
Server-2: PipeWire v: 0.3.65 status: active with: 1: pipewire-pulse status: active
2: wireplumber status: active 3: pipewire-alsa type: plugin
Network:
Device-1: Broadcom NetXtreme II BCM5709 Gigabit Ethernet driver: bnx2 v: kernel pcie:
speed: 2.5 GT/s lanes: 4 port: N/A bus-ID: 04:00.0 chip-ID: 14e4:1639
IF: enp4s0f0 state: down mac: <filter>
Device-2: Broadcom NetXtreme II BCM5709 Gigabit Ethernet driver: bnx2 v: kernel pcie:
speed: 2.5 GT/s lanes: 4 port: N/A bus-ID: 04:00.1 chip-ID: 14e4:1639
IF: enp4s0f1 state: down mac: <filter>
Device-3: Intel Wi-Fi 6 AX200 driver: iwlwifi v: kernel pcie: speed: 5 GT/s lanes: 1
bus-ID: 06:00.0 chip-ID: 8086:2723
IF: wlp6s0 state: up mac: <filter>
Device-4: Realtek RTL8125 2.5GbE vendor: ASUSTeK driver: r8169 v: kernel pcie: speed: 5 GT/s
lanes: 1 port: f000 bus-ID: 07:00.0 chip-ID: 10ec:8125
IF: enp7s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Bluetooth:
Device-1: Intel AX200 Bluetooth type: USB driver: btusb v: 0.8 bus-ID: 1-5:2 chip-ID: 8087:0029
Report: hciconfig ID: hci0 rfk-id: 0 state: up address: <filter> bt-v: 3.0 lmp-v: 5.2
sub-v: 200f
Drives:
Local Storage: total: 4.11 TiB used: 54.1 GiB (1.3%)
ID-1: /dev/nvme0n1 vendor: Western Digital model: WDBRPG0010BNC-WRSN size: 931.51 GiB
speed: 31.6 Gb/s lanes: 4 serial: <filter> temp: 45.9 C
ID-2: /dev/nvme1n1 vendor: Western Digital model: WD BLACK SN850 1TB size: 931.51 GiB
speed: 63.2 Gb/s lanes: 4 serial: <filter> temp: 44.9 C
ID-3: /dev/sda vendor: Western Digital model: WDBNCE0010PNC size: 931.51 GiB speed: 6.0 Gb/s
serial: <filter>
ID-4: /dev/sdb vendor: Western Digital model: WD10EZEX-22MFCA0 size: 931.51 GiB speed: 6.0 Gb/s
serial: <filter>
ID-5: /dev/sdc vendor: Western Digital model: WDBNCE5000PNC size: 465.76 GiB speed: 6.0 Gb/s
serial: <filter>
ID-6: /dev/sdd type: USB vendor: PNY model: USB 2.0 FD size: 14.46 GiB serial: <filter>
Partition:
ID-1: / size: 883.82 GiB used: 27.05 GiB (3.1%) fs: ext4 dev: /dev/dm-0 mapped: lvmlmde-root
ID-2: /boot/efi size: 285.4 MiB used: 5.8 MiB (2.0%) fs: vfat dev: /dev/nvme0n1p1
Swap:
Alert: No swap data was found.
Sensors:
System Temperatures: cpu: 38.9 C mobo: N/A gpu: amdgpu temp: 43.0 C mem: 40.0 C
Fan Speeds (RPM): N/A gpu: amdgpu fan: 0
Repos:
Packages: 3119 pm: dpkg pkgs: 3059 pm: flatpak pkgs: 60
No active apt repos in: /etc/apt/sources.list
Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
1: deb http: //packages.linuxmint.com faye main upstream import backport
2: deb https: //deb.debian.org/debian bookworm main contrib non-free non-free-firmware
3: deb https: //deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
4: deb http: //security.debian.org/ bookworm-security main contrib non-free non-free-firmware
5: deb https: //deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
Info:
Processes: 357 Uptime: 1h 6m Memory: 31.23 GiB used: 1.97 GiB (6.3%) Init: systemd v: 252
target: graphical (5) default: graphical Compilers: gcc: 12.2.0 alt: 12 Client: Unknown
python3.11 client inxi: 3.3.26
 

Members online


Latest posts

Top