Set Up CUPS Print Server on CentOS 8/RHEL 8 (Bonjour, IPP, Samba, AirPrint)

This tutorial will be showing you how to share a printer attached to a CentOS 8/RHEL 8 computer with Windows, macOS, and iOS clients on the same network. CUPS (Common Unix Printing System) is the default printing system on Linux, FreeBSD, and macOS. Your Linux desktop environment may have a dedicated printer configuration utility, but they all use CUPS under the hood. CUPS printer can be shared on the network using several protocols, including:

  • Bonjour + IPP: Bonjour, also known as mDNS/DNS-SD (multicast DNS/DNS service discovery), allows a computer to find services on the local network. IPP (Internet Printing Protocol) is the transport protocol.
  • SMB: aka Samba, mainly used to share files and printers with Windows clients.
  • AirPrint: Allows iPhone, iPad, and macOS clients to print over Wi-Fi.

Each protocol has its advantages and disadvantages. First, I will show you how to install and configure CUPS. Then we will learn how to share the CUPS printer via the above 3 protocols. I recommend using all 3 methods to share your printer, so users can find an available printer on the local network with minimal effort.

Set Up CUPS Print Server on CentOS 8 RHEL 8

Step 1: Install and Configure CUPS on CentOS 8/RHEL 8

CentOS 8/RHEL 8 desktop edition has CUPS pre-installed. If you use CentOS 8/RHEL 8 server edition, you need to run the following command to install CUPS from the default CentOS 8/RHEL 8 repository.

sudo dnf install cups

Then start CUPS.

sudo systemctl start cups

Enable auto-start at boot time.

sudo systemctl enable cups

Check its status:

systemctl status cups

Sample output:

cups-printing-system-centos8-rhel8

Next, edit the CUPS main configuration file with a command-line text editor like Nano.

sudo nano /etc/cups/cupsd.conf

By default, the CUPS web interface is only available at localhost:631. If you are running CentOS 8/RHEL 8 server edition, you might want to make CUPS listen on all available network interface, so that you will be able to access the CUPS web interface from other computers. Find the following line.

Listen localhost:631

Change it to the following, So CUPS will listen on all network interfaces.

Port 631

The following line will make CUPS show shared printers on the local network, so other computers in the same network can see printers connected to your CentOS 8/RHEL 8 computer.

Browsing On

Then find the following lines.

<Location />
  Order allow,deny
</Location>

The above configuration only allows access to the CUPS web interface from localhost. To allow access from other computers in the same network, add Allow @LOCAL to the configuration like below.

<Location />
  Order allow,deny
  Allow @LOCAL
</Location>

If you want to allow remote administration from local network, also add it for the /admin directory.

<Location /admin>
  Order allow,deny
  Allow @LOCAL
</Location>

Save and close the file. Then restart CUPS for the changes to take effect.

sudo systemctl restart cups

We need to allow clients in the same network to access port 631 on your CentOS 8/RHEL 8 computer.

sudo firewall-cmd --permanent --add-port=631/tcp

Reload firewall for the change to take effect.

sudo systemctl reload firewalld

In addition to the main cups.service, there’s also cups-browsed.service, which is used to scan and add printer from the local network. If you want your CentOS 8/RHEL 8 computer to be able to use other printers on the local network, start this service.

sudo systemctl start cups-browsed

And enable auto-start at boot time.

sudo systemctl enable cups-browsed

Step 2: Install Driver for Your Printer on CentOS 8/RHEL 8

You need to install driver on CentOS 8/RHEL 8, so it can recognize and use the printer. If you have an HP printer, you can easily install the driver with the following command.

sudo dnf install hplip

I also recommend installing the gutenprint-cups package, which provides CUPS drivers for Canon, Epson, HP and compatible printers.

sudo dnf install gutenprint-cups

If you have other printers, you can find drivers on openprinting.org.

After installing the driver, you may need to re-connect the printer to the USB port of your CentOS 8/RHEL 8 computer. To test if the driver is working correctly, you can create a text file on CentOS 8/RHEL 8:

echo "LinuxBabe is awesome!" > file.txt

Then run the following command to print this text file from the command line.

lp file.txt

This is a very rudimentary method, so don’t worry about printing quality now.

Step 3: Share CUPS Printer via Bonjour/IPP Protocol

Installing Avahi-daemon

CUPS can announce its presence on the network via mDNS (multicast DNS) and DNS-SD (DNS Service Discovery) protocol, which is also known as Bonjour. In order to do that, you need to install and run avahi-daemon, which is a service similiar to the Apple Bonjour service that allows computers to automatically discover shared devices and services on the local network.

sudo dnf install avahi

We also need to install the nss-mdns package from EPEL repository, which is needed for clients to resolve .local domain on the network.

sudo dnf install epel-release

sudo dnf install nss-mdns

Start avahi-daemon.

sudo systemctl start avahi-daemon

Enable auto-start at boot time.

sudo systemctl enable avahi-daemon

Avahi-daemon listens on UDP port 5353. Open it in the firewall.

sudo firewall-cmd --permanent --add-port=5353/udp

Reload firewall for the change to take effect.

sudo systemctl reload firewalld

IPP Driverless Printing

Bonjour is used to advertise the printer on the local network. To make clients and the CUPS server communicate with each other, IPP (Internet Printing Protocol) is needed. The advantage of IPP is that clients can use the shared printer without installing any driver on their own devices. CUPS supports IPP out of the box, so you don’t need to do anything else to share CUPS printer via IPP.

Step 4: Add Printer on Client Computers

macOS and Linux Clients

Because macOS and most Linux desktop distributions have CUPS installed as the default printing system, once you have enabled printer sharing via Bonjour/IPP on the CentOS 8/RHEL 8 box, macOS and Linux users in the same network can automatically use the printer. When they click the print option in applications (word processors, email readers, photo editors, and web browsers), the printer will be automatically available. They don’t have to explicitly add the printer. It’s magic.

If your Linux computer can’t find the printer, it’s possible that your system doesn’t have the ippfind command. Run the following command to install it on Debian-based Linux distribution.

sudo apt install cups-ipp-utils

On CentOS 8, run the following command.

sudo dnf install cups-ipptool

Then restart CUPS on the client computer.

sudo systemctl restart cups

Windows

Windows 10 ships with an IPP client. Type in printer in the lower-left search bar and open Printers & Scanners. Then click the Add a printer or scanner button. It will scan available printers on the local network.

windows 10 printers & scanners

As you can see, it found my HP Deskjet printer. Select the found printer and click Add device. It will be added to the printer list in a few moments.

If you are using a different version of Windows that can’t add printer this way, then you can install the Bonjour Print services. Once installed, launch the Bonjour printer wizard. It will automatically scan available printers on the local network. As you can see from the screenshot, it found my HP printer.

add bonjour printer on windows

Click next, then you need to choose a driver for this printer. You can choose the Microsoft IPP class driver, which is installed on the system by default.

microsoft IPP class driver

Click Next, and the printer will be added to your Windows system.

Manually Adding Printer on Linux

If for any reason you don’t see the printer, you can manually add one. To add a Bonjour-shared printer on desktop Linux, search your system settings or the application menu for the printer configuration utility. Click the Add button to add a new printer.

add cups printer on linux

Then click Network Printer, and it would automatically scan available printers on the local network. As you can see, it found my HP Deskjet printer. Click the Forward button.

cups centos 8 dnssd

Then you can give the printer a name and description. I simply accept the default values. Click Apply and you are done.

centos 8 cups printer mdns dnssd

Manually Adding Printer on macOS

To add a Bonjour-shared printer on macOS, go to system preferences -> Printers & Scanners. Click the plus (+) button to add a printer.

add a bonjour printer on macOS

It would automatically scan available printers on the local network. As you can see, it found my HP Deskjet printer.

macOS bonjour printer

Click the Add button and it will appear in the printer list.

macOS printers & scanners

Step 5: Share CUPS Printer via Samba

Samba is a free and open-source SMB/CIFS protocol implementation for Unix and Linux that allows for file and print sharing between Unix/Linux and Windows machines in a local area network. It’s mainly used to share files and printer with Windows clients.

To install Samba on CentOS 8/RHEL 8, run the following command.

sudo dnf install samba

Then issue the following command to start the smbd and nmbd service.

sudo systemctl start smb nmb

Enable auto-start at boot time.

sudo systemctl enable smb nmb

To check if Samba service is running, issue the following commands.

systemctl status smb nmb

Once started, the smb daemon will be listening on TCP port 139 and 445. The nmbd will be listening on UDP port 137 and 138. Run the following command to open these ports in the firewall.

sudo firewall-cmd --permanent --add-service=samba

Reload firwall daemon for the change the take effect.

sudo systemctl reload firewalld

Then edit the main configuration file.

sudo nano /etc/samba/smb.conf

Find the [printers] section. By default, it looks like this:

[printers]
        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = No

We need to change the value of browseable to yes, so clients in the same network can find the printer and add guest ok = yes to allow anyone in the network to use the printer.

[printers]
        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = yes
        guest ok = yes

It’s recommended to enable the spoolssd service when sharing printer. This will make Samba more efficient when there’s lots of printing jobs. Simply add the following two lines in the [global] section to enable the spoolssd service.

 rpc_server:spoolss = external
 rpc_daemon:spoolssd = fork

Save and close the file. Then restart Samba.

sudo systemctl restart smb nmb

Adding a Samba-shared Printer in Windows.

Open file explorer, enter the IP address of the CentOS 8/RHEL 8 computer in the address bar like \\192.168.0.110. The printer should now be listed.

add samba-shared printer on Windows 10

Double-click the printer to add it to your Windows system. Then click OK button to select a driver to install. After installing the driver, the printer will be added to your Windows system.

windows add printer wizard

Step 6: Share CUPS Printer with iOS Clients via AirPrint

AirPrint allows iPhone, iPad, and macOS clients to print over Wi-Fi without installing driver software on the client devices. CUPS supports Airprint, but avahi-daemon by default doesn’t announce AirPrint service on the local network. We need to create a .service file in the /etc/avahi/services/ directory for the printer with a Python script. Run the following command to download the script on CentOS 8/RHEL 8.

wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py

Add execute permission.

chmod +x airprint-generate.py

This python script is made for Python2. CentOS 8/RHEL 8 uses Python3 by default. We need to install Python2.

sudo dnf install python2

Edit this file.

nano airprint-generate.py

Change

#!/usr/bin/env python

to

#!/usr/bin/env python2

Save and close the file. Then install dependencies.

sudo dnf install gcc python2-devel cups-devel redhat-rpm-config

Install the cups module.

sudo pip2 install cups pycups

Then run this script.

sudo ./airprint-generate.py -d /etc/avahi/services/

Now there should a .service file under /etc/avahi/services/ directory for your printer.

ls /etc/avahi/services/

Sample output:

AirPrint-DeskJet-2130-series.service

Restart Avahi-daemon.

sudo systemctl restart avahi-daemon

Now iOS and macOS clients in the same network should be able to use your printer. The following screenshot shows my iPhone successfully found an AirPrint Printer.

centos 8 cups airprint

Wrapping Up

I hope this tutorial helped you set up a CUPS print server on CentOS 8/RHEL 8. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. And you may also want to read the following article to set up a Samba file share server.

Rate this tutorial
[Total: 12 Average: 5]

12 Responses to “Set Up CUPS Print Server on CentOS 8/RHEL 8 (Bonjour, IPP, Samba, AirPrint)

  • Jason Peters
    4 years ago

    Airprint install fails for me at pip2 install cups pycups.

    • Donnie Darko
      4 years ago

      Instead of installing the latest version of pycups, try this instead:

      pip2 install cups
      pip2 install pycups==1.9.74
      • Jason Peters
        4 years ago

        That worked!!

        Pip2 install Pycups==1.9.74

        Thanks!

  • Alvin Murphy
    4 years ago

    I ran into the same problem:

    Command “/usr/bin/python2 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-DyrOUy/pycups/setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-mxrzka-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-DyrOUy/pycups/

  • On Centos 8 to install CUPS-PDF follow these steps as root:
    yum update
    yum -y install cups gcc gcc-c++ cups-devel tar wget
    wget https://www.cups-pdf.de/src/cups-pdf_3.0.1.tar.gz
    tar -xvf cups-pdf_3.0.1.tar.gz
    cd cups-pdf-3.0.1/src/
    gcc -O9 -s cups-pdf.c -o cups-pdf -lcups
    chmod 700 cups-pdf
    cp -p cups-pdf /usr/lib/cups/backend/
    cd ../extra
    cp cups-pdf.conf /etc/cups/
    cp CUPS-PDF_opt.ppd /usr/share/cups/model/
    firewall-cmd –zone=public –add-port=631/tcp –permanent
    firewall-cmd –reload
    sed -i “s/Allow \@LOCAL/Allow all/g” /etc/cups/cupsd.conf
    systemctl restart cups
    systemctl enable cups
    cupsctl –remote-admin

  • Airprintgenerate.py built for me in python3 after editing the file to change

    f = open(fname, 'w')
    to
    f= open(fname, 'wb')
    

    see https://github.com/tjfontaine/airprint-generate/issues/26

    • @chris: it doesn’t work on CentOS 8.2 with python3 and your change

      Traceback (most recent call last):
      File “./airprint-generate.py”, line 263, in
      cups.setPasswordCB(getpass)
      AttributeError: module ‘cups’ has no attribute ‘setPasswordCB’

      @Donnie Darko
      Installation with old version works, but following error is shown:

      Traceback (most recent call last):
      File “./airprint-generate.py”, line 26, in
      import urllib.parse as urlparse
      ImportError: No module named parse

      The current script points to python3 instead python in the manual and I can’t install pycups (newest or old version) with pip3

  • Is python3 pyCups for your system installed? (I’m using Fedora, you’re using CentOS. I know they are similar, but not the same.)

    Installed Packages
    Name : python3-cups
    Version : 2.0.1
    Release : 5.fc33
    Architecture : x86_64
    Size : 235 k
    Source : python-cups-2.0.1-5.fc33.src.rpm
    Repository : @System
    From repo : fedora
    Summary : Python3 bindings for CUPS API, known as pycups.
    URL : https://github.com/OpenPrinting/pycups/
    License : GPLv2+
    Description : This package provides Python 3 bindings for CUPS API,
    : known as pycups. It was written for use with
    : system-config-printer, but can be put to other uses as well.

  • On Fedora 31, had to edit airprint-generate.py and add ‘b’ to open line on line 223:

    f = open(fname, ‘wb’)

    as the script was erroring with “TypeError: write() argument must be str, not bytes”.

  • How to setup a high availability CUPS service

  • Charles Halsall
    5 days ago

    I migrated from Centos 6 to Rock 8. What am I missing? I followed the instructions to a T and still can’t get the printer shares to show up. Could this be some sort of permission issue, maybe a selinux thing?

    Stuff like this should be a no-brainer.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here