fbpx

Solutions

How to share printers using Avahi and cups-browsed in CentOS 7.7

by ,


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Operating System and Software

  • CentOS 7.7+ / Common Unix Printing System (CUPS) 1.6.3 / cups-filters-1.0.35-26.el7 (and later versions)
  • Rocky Linux 8 / CUPS 2.2.6 / cups-filters-1.20.0

Problem

How can I use Avahi and cups-browsed to share printers in CentOS 7.7 and Rocky Linux 8

How to Fix

This method of printer sharing and discovery uses a set of service protocols (“multicast DNS” and “DNS Service Discovery”) that enables clients to discover shared printers on the master servers. The mDNS/DNS-SD protocols are implemented using Avahi and D-Bus in CentOS 7 and Rocky Linux 8. This method of printer sharing should be compatible with the Apple-branded “Bonjour” (sometimes called “Zeroconf”) system found in MacOS X.

For other methods of printer sharing and discovery using CUPS, please see the following Knowledgebase Solution:

How do I set up a master print server using CUPS in RHEL?

CUPS Master Print Server Configuration

  1. Stop CUPS and back up your current CUPS configuration:

    # service cups stop
    # cp -a /etc/cups /etc/cups.saved
    
  2. Edit /etc/cups/cupsd.conf to allow other servers to connect to printers on the master server. First change:

    Listen localhost:631
    

    to:

    Listen *:631
    

    or

    Listen 0.0.0.0:631
    

    This will configure CUPS to listen on all network interfaces. If you would like to limit CUPS to listening on a particular interface, enter the IP address of that interface instead of * or 0.0.0.0. For example:

    Listen 192.168.102.32:631
    
  3. In cupsd.conf, add Allow @LOCAL to the bottom of the <Location /> stanza so It looks like the following:

    <Location />
      # Allow shared printing
      Order allow,deny
      Allow @LOCAL
    </Location>
    

    This will allow clients on the “local” network (the subnet on which the Master Print Server is located) to access CUPS on the Master Print Server. If you would like all clients to access the Master Print Server, then use “Allow all” instead of “Allow @Local“.

  4. Install, enable, and start the D-Bus service. It’s probable that D-Bus is already installed and started. You can check this with the systemctl status command:

    # systemctl status dbus.service
    ● dbus.service - D-Bus System Message Bus
       Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
       Active: active (running) since Wed 2020-01-29 12:47:18 PST; 23h ago
    

    If the D-Bus service is not loaded and active, the following commands should install and start it:

    yum install dbus dbus-libs
    systemctl enable dbus.service
    systemctl restart dbus.service
    
  5. Install, enable, and start Avahi service:

    yum install avahi
    systemctl enable avahi-daemon.service
    systemctl restart avahi-daemon.service
    
  6. Stop and disable the “cups-browsed” service. It is not required as CUPS will communicate printer status to Avahi via D-Bus:

    systemctl stop cups-browsed
    systemctl disable cups-browsed
    
  7. Start and enable CUPS:

    systemctl enable cups.service
    systemctl restart cups.service
    

    More information about CUPS printer browsing in CentOS 7 and later versions can be found in the following Knowledgebase Solution:

    CUPS Printer Browsing in CentOS 7

  8. Make sure that each of your locally defined print queues is shared. The default is to share queues when they are created, so this shouldn’t be a problem. You can check the sharing status of a print queue by running the lpoptions command and looking for the printer-is-shared option as follows:

    # lpoptions -p textonly
    copies=1 device-uri=socket://10.3.4.5/ finishings=3 job-hold-until=no-hold job-priority=50 job-sheets=none,none
    marker-change-time=0 number-up=1 printer-commands=none printer-info=textonly printer-is-accepting-jobs=true
    printer-is-shared=true printer-location printer-make-and-model='Generic text-only printer' printer-state=3
    printer-state-change-time=1478741330 
    printer-state-reasons=none printer-type=4100
    printer-uri-supported=ipp://localhost:631/printers/textonly
    

    Note the entry printer-is-shared=true on the 3rd line in the output of the command above. You can also use the grep command to extract the value of printer-is-shared:

    # lpoptions -p textonly | egrep -o 'printer-is-shared=[^ ]+'
    printer-is-shared=true
    

    If the printer is not shared (i.e. the lpoptions command returns printer-is-shared=false), then the following command should share the printer:

    # lpatmin -p textonly -o printer-is-shared=true -E
    
  9. Check to see that printers are defined and enabled on the master print server

    # lpstat -t
    scheduler is running
    no system default destination
    device for pcl: socket://10.1.2.3/
    device for postscript: socket://10.2.3.4/
    device for textonly: socket://10.3.4.5/
    pcl accepting requests since Wed 09 Nov 2016 05:28:19 PM PST
    postscript accepting requests since Wed 09 Nov 2016 05:28:37 PM PST
    textonly accepting requests since Wed 09 Nov 2016 05:28:50 PM PST
    printer pcl is idle.  enabled since Wed 09 Nov 2016 05:28:19 PM PST
    printer postscript is idle.  enabled since Wed 09 Nov 2016 05:28:37 PM PST
    printer textonly is idle.  enabled since Wed 09 Nov 2016 05:28:50 PM PST
    
  10. If you have a firewall enabled on the master print server, reconfigure the firewall to allow outside access to port 631/ipp (as well as port 5353/mdns for CentOS 7) via UDP and TCP. Please refer to the appropriate RHEL Installation and Deployment Guides on how to do this for your particular version of RHEL.

CUPS Client Service Configuration

  1. Install, enable, and start the D-Bus service. It’s probable that D-Bus is already installed and started. You can check this with the systemctl status command:

    # systemctl status dbus.service
    ● dbus.service - D-Bus System Message Bus
       Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
       Active: active (running) since Wed 2020-01-29 12:47:18 PST; 23h ago
    

    If the D-Bus service is not loaded and active, the following commands should install and start it:

    yum install dbus dbus-libs
    systemctl enable dbus.service
    systemctl restart dbus.service
    
  2. Install, enable, and start the Avahi service:

    yum install avahi
    systemctl enable avahi-daemon.service
    systemctl start avahi-daemon.service
    
  3. Install the NSS (Name Service Switch) mDNS (multicast DNS) plugin for glibc. This is required to resolve the .local names that Avahi uses:

    yum install nss-mdns
    
  4. Make sure CUPS is started and enabled:

    systemctl enable cups.service
    systemctl start cups.service
    

Once the above steps are completed, the printers shared by the Master Print Server(s) should appear on the Client system:

# lpstat -t
scheduler is running
no system default destination
device for pcl: implicitclass:pcl
device for postscript: implicitclass:postscript
device for textonly: implicitclass: textonly
pcl accepting requests since Wed 09 Nov 2016 05:28:19 PM PST
postscript accepting requests since Wed 09 Nov 2016 05:28:37 PM PST
textonly accepting requests since Wed 09 Nov 2016 05:28:50 PM PST
printer pcl is idle.  enabled since Wed 09 Nov 2016 05:28:19 PM PST
printer postscript is idle.  enabled since Wed 09 Nov 2016 05:28:37 PM PST
printer textonly is idle.  enabled since Wed 09 Nov 2016 05:28:50 PM PST

The printers shared from the Master Print Server(s) use the implicitclass backend, as described in the following Knowledgebase Solution:

Running “lpstat -s” shows “implicitclass” in CentOS 7.7

Diagnostic Steps

If the DebugLogging file directive is set in /etc/cups/cups-browsed.conf, then the following messages will appear in /var/log/cups/cups-browsed_log when Avahi is being used for printer sharing:

Wed Jan 29 14:42:15 2020 Avahi server connection got available, setting up service browsers.
Wed Jan 29 14:42:15 2020 listening
Wed Jan 29 14:42:15 2020 Avahi Browser: NEW: service 'test @ rhel77-master' of type '_ipp._tcp' in domain 'local'
Wed Jan 29 14:42:15 2020 Avahi Browser: CACHE_EXHAUSTED
Wed Jan 29 14:42:15 2020 Avahi Browser: ALL_FOR_NOW
Wed Jan 29 14:42:15 2020 Avahi Browser: NEW: service 'test @ rhel77-master' of type '_ipps._tcp' in domain 'local'
Wed Jan 29 14:42:15 2020 Avahi Browser: CACHE_EXHAUSTED
Wed Jan 29 14:42:15 2020 Avahi Browser: ALL_FOR_NOW
Wed Jan 29 14:42:15 2020 Avahi Resolver: Service 'test @ rhel77-master' of type '_ipp._tcp' in domain 'local'.
Wed Jan 29 14:42:15 2020 Found CUPS queue: test on host rhel77-master.local.
Wed Jan 29 14:42:15 2020 cups-browsed [BrowsePoll /var/run/cups/cups.sock:631]: IPP-Get-Notifications
Wed Jan 29 14:42:15 2020 cups-browsed [BrowsePoll /var/run/cups/cups.sock:631]: no events
Wed Jan 29 14:42:15 2020 Matching printer "test" with properties Host = "rhel77-master.local", Port = 631,
                         Service Name = "test @ rhel77-master", Domain = "local" with the BrowseFilter lines in cups-browsed.conf
Wed Jan 29 14:42:15 2020 All BrowseFilter lines matched or skipped, accepting printer test
Wed Jan 29 14:42:15 2020 Bonjour IDs: Service name: "test @ rhel77-master", Service type: "_ipp._tcp", Domain: "local"
Wed Jan 29 14:42:15 2020 checking queues in 0s
Wed Jan 29 14:42:15 2020 Avahi Resolver: Service 'test @ rhel77-master' of type '_ipps._tcp' in domain 'local'.
Wed Jan 29 14:42:15 2020 Found CUPS queue: test on host rhel77-master.local.
Wed Jan 29 14:42:15 2020 cups-browsed [BrowsePoll /var/run/cups/cups.sock:631]: IPP-Get-Notifications
Wed Jan 29 14:42:15 2020 cups-browsed [BrowsePoll /var/run/cups/cups.sock:631]: no events
Wed Jan 29 14:42:15 2020 Matching printer "test" with properties Host = "rhel77-master.local", Port = 631,
                         Service Name = "test @ rhel77-master", Domain = "local" with the BrowseFilter lines in cups-browsed.conf
Wed Jan 29 14:42:15 2020 All BrowseFilter lines matched or skipped, accepting printer test
Wed Jan 29 14:42:15 2020 Entry for test (URI: ipp://rhel77-master.local:631/printers/test) already exists.
Wed Jan 29 14:42:15 2020 Upgrading printer test (Host: rhel77-master.local, Port :631) to IPPS.
                         New URI: ipps://rhel77-master.local:631/printers/test
Wed Jan 29 14:42:15 2020 Bonjour IDs: Service name: "test @ rhel77-master", Service type: "_ipps._tcp", Domain: "local"

The terms Avahi Browser, Avahi Resolver indicate that the Avahi service is being used to discover remote print queues.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.