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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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.