If your company has multiple PCs on the network that need to print, we need a device called a print server. Print servers act between the PC and printers, which accept print jobs from the PC and send them to the appropriate printer.
CUPS is the primary mechanism in the Unix-like operating system for printing and printing services. It can allow a computer to act as a print server.
In this tutorial we will learn how to set up the CUPS print server on Ubuntu 20.04.
requirements
- An Ubuntu Server 20.04 computer that has a network connection to the printer
- A client Ubuntu desktop or server edition to access the printer
1. Install CUPS on Ubuntu
CUPS is the default printing system in most Linux distributions, including Ubuntu. It supports print jobs, queues, network printing (with IPP), supports a wide variety of printers, auto-detection of network printers, web administration and more.
First, get your Ubuntu system update:
$ sudo apt update
CUPS is installed by default in the Ubuntu Desktop Edition. To install cups on the Ubuntu Server Edition, enter the following command on your terminal:
$ sudo apt install cups
Start the cups daemon:
$ sudo systemctl start cups
Make sure the daemon is running:
$ sudo systemctl status cups
Output:
● cups.service - CUPS Scheduler Loaded: loaded (/lib/systemd/system/cups.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2021-08-15 01:31:30 WAT; 53min ago TriggeredBy: ● cups.socket ● cups.path Docs: man:cupsd(8) Main PID: 971 (cupsd) Status: "Scheduler is running…" Tasks: 1 (limit: 18958) Memory: 26.3M ...
Also activate the cups daemon to start at boot:
$ sudo systemctl enable cups
2. Configure CUPS under Ubuntu
CUPS can be configured via the web interface (available at http: // localhost: 631 / admin) or via the instructions in the /etc/cups/cupsd.conf file. Let’s see how to configure the CUPS configuration file to set up a print server.
First back up the configuration file by saving a copy of the default configuration. This is in case something goes wrong and you want to undo things.
$ sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.copy
Open the original file with your favorite editor and modify the following.
So that CUPS can listen on all network interfaces, deactivate the line Listen localhost: 631 (under the section ‘Only listen for connections from the local computer’) and add the line Port 631 as follows:
#Listen localhost:631 Port 631
Make sure that the instruction Browsing On is activated in order to display the shared printers in the local network (in the section ‘Show shared printers in the local network’):
Browsing On
Set BrowseLocalProtocols to the dnsd protocol (which Bonjour supports), by default it is enabled.
BrowseLocalProtocols dnssd
In the “Restrict access to the server” section, add @LOCAL to allow access from other computers on the network.
#Restrict access to the serverOrder allow,deny Allow @LOCAL
Under “Restrict access to the administrator pages” add the directory / admin to enable access to the administrator pages from another computer.
#Restrict access to the admin pages.Order allow,deny Allow @LOCAL
Save and close the file. Then restart the cups daemon for the changes to take effect:
$ sudo systemctl restart cups
If you prefer the configuration with the CUPS web interface, it is recommended to use either root or a user authenticated in the lpadmin group.
Enter the following to add a user to the lpadmin group:
$ sudo usermod -aG lpadmin username
3. Install your printer driver
Most HP printers work on Linux by default. HP drivers are called hplip and are already installed on most Linux distributions.
Note: Before installing the driver, try to start the CUPS service to see if it automatically detects the printer.
If not installed, use the following command to install the HP driver:
$ sudo apt install hplip
Additional printer drivers can be found on openprinting.org.
4. Install Bonjour to share the CUPS printer
We have already instructed the cups daemon to make printing a recognizable service in the network using the Bonjour protocol (DNSSD).
For printer service discovery, you need to install avahi-daemon, which has mDNS / DNS-SD service discovery. avahi-daemon is a Bonjour server that transmits your computer’s information over the network. It enables CUPS to publish / discover services and hosts running on a local network without any specific configuration.
To install avahi-daemon on Ubuntu, enter:
$ sudo apt install avahi-daemon
To start the Avahi daemon, enter:
$ sudo systemctl start avahi-daemon
Now you can activate the Avahi daemon at boot:
$ sudo systemctl enable avahi-daemon
Check the running Avahi daemon:
$ sudo sytemctl status avahi-daemon
Output showing 192.168.43.105 as one of the service endpoints on the network:
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2021-08-15 09:45:44 WAT; 11s ago TriggeredBy: ● avahi-daemon.socket Main PID: 11518 (avahi-daemon) Status: "avahi-daemon 0.8 starting up." Tasks: 2 (limit: 18958) Memory: 1.0M ... Aug 15 09:45:44 user-HP-EliteBook-Folio-9470m avahi-daemon[11518]: Registering new address record for 192.168.43.105 on wlo1.IPv4. ... Aug 15 09:45:45 user-HP-EliteBook-Folio-9470m avahi-daemon[11518]: Server startup complete. Host name is user-HP-EliteBook-Folio-9470m.local.
Unlock port
If you’ve enabled a firewall, make sure that the client’s computers are communicating on CUPS port 631.
Suppose ufw is your firewall program:
$ sudo ufw allow 631/tcp
As well as UDP port 5353 for Avahi daemon:
$ sudo ufw allow 5353/udp
Add a printer on the client computer
Let’s see how to add the remote printer on an Ubuntu client computer that will be shared through the CUPS print server.
To interpret Bonjour broadcasts from the CUPS print server, the clients can use cups-browsed (part of CUPS – supports IPP) or avahi-client (which is installed by default). IPP is required for print management and helps client computers use shared printers without installing drivers.
The cups-browsed daemon automatically finds the shared printer in the network; normally you do not have to add the printer.
If your client is an Ubuntu server edition, make sure you install (most Linux distributions have CUPS pre-installed), enable and start cups.
$ sudo apt install cups $ sudo systemctl start cups && sudo systemctl enable cups
If the remote printer was not detected automatically, then added it manually.
Press your window key and go to Settings> Printers.
Click the Add button.
Add the IP address or name of the print server and click the Search button.
Select the printer from the list and click the Forward button.
Enter a brief description for your printer and click the Apply button.
You can run a test print from the command line with the lp command and watch the magic:
$ lp document.txt
diploma
In this tutorial we learned how to set up a CUPS print server on Ubuntu 20.04. Please share your feedback and suggestion in the comments section.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.