Set Up CUPS Print Server on Ubuntu (Bonjour, IPP, Samba, AirPrint)
This tutorial will be showing you how to share a printer attached to an Ubuntu 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.
Step 1: Install and Configure CUPS on Ubuntu
Ubuntu desktop edition has CUPS pre-installed. If you use Ubuntu server edition, you need to run the following command to install CUPS from the default Ubuntu repository.
sudo apt 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:
Next, edit the CUPS main configuration file with a command-line text editor like Nano.
sudo nano /etc/cups/cupsd.conf
First, we need to show shared printers on the local network. Find the following line.
Browsing Off
Change it to
Browsing On
so other computers in the same network can see printers connected to your Ubuntu computer.
By default, the CUPS web interface is only available at localhost:631
. If you are running Ubuntu server edition, you may also 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
Port 631
So CUPS will listen on all network interfaces. Then find the following lines.
<Location /> Order allow,deny </Location>
The above configuration allows access to the CUPS web interface from localhost only. 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>
Also add it for the /admin
directory to allow remote administration from local network.
<Location /admin> Order allow,deny Allow @LOCAL </Location>
You can also allow a particular IP address like so:
<Location /> Order allow,deny Allow 192.168.0.101 </Location>
Save and close the file. Then restart CUPS for the changes to take effect.
sudo systemctl restart cups
Note that if you have enabled the UFW firewall on Ubuntu, you need to allow clients in the same network to access port 631 on your Ubuntu box. For example, my private network is using the 192.168.0.0 ~192.168.0.255 network range, so I run the following command.
sudo ufw allow in from 192.168.0.0/24 to any port 631
The CUPS web interface is available at https://IP-address-of-Ubuntu-box:631
. We don’t need to use the web interface in this article, but if you want to use it, then you need to add your user account to the lpadmin
group in order to make changes in the CUPS web interface.
sudo adduser your_username lpadmin
Step 2: Install Driver for Your Printer on Ubuntu
You need to install driver on Ubuntu, 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 apt install hplip
I also recommend installing the printer-driver-gutenprint
package, which provides CUPS drivers for Canon, Epson, HP and compatible printers.
sudo apt install printer-driver-gutenprint
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 Ubuntu computer. To test if the driver is working correctly, you can create a text file on Ubuntu:
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 apt install avahi-daemon
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 ufw allow 5353/udp
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 Ubuntu 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.
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.
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.
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.
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.
Then you can give the printer a name and description. I simply accept the default values. Click Apply and you are done.
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.
It would automatically scan available printers on the local network. As you can see, it found my HP Deskjet printer.
Click the Add button and it will appear in the printer list.
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 Ubuntu, simply run the following command in terminal.
sudo apt install samba samba-common-bin
To check if Samba service is running, issue the following commands.
systemctl status smbd systemctl status nmbd
To start these two services, issue the following commands:
sudo systemctl start smbd sudo systemctl start nmbd
Then edit the main configuration file.
sudo nano /etc/samba/smb.conf
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
Next, go to the end of the file and you will see the [printers]
section. In Nano text editor, you can jump to the end of a file by pressing Ctrl+W
, then Pressing Ctrl+V
. Find the following two lines.
browseable = no guest ok = no
Change them to
browseable = yes guest ok = yes
Save and close the file. Then restart Samba.
sudo systemctl restart smbd nmbd
Adding a Samba-shared Printer in Windows.
Open file explorer, enter the IP address of the Ubuntu computer in the address bar like \\192.168.0.110
. The printer should now be listed.
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.
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 with the following command. My printer’s model is DeskJet 2130 series. Replace it with your own model name.
sudo nano /etc/avahi/services/AirPrint-DeskJet-2130-series.service
Add the following lines in the file.
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">AirPrint DeskJet-2130-series @ %h</name> <service> <type>_ipp._tcp</type> <subtype>_universal._sub._ipp._tcp</subtype> <port>631</port> <txt-record>txtvers=1</txt-record> <txt-record>qtotal=1</txt-record> <txt-record>Transparent=T</txt-record> <txt-record>URF=none</txt-record> <txt-record>rp=printers/DeskJet-2130-series</txt-record> <txt-record>note=HP DeskJet 2130 series</txt-record> <txt-record>product=(GPL Ghostscript)</txt-record> <txt-record>printer-state=3</txt-record> <txt-record>printer-type=0x2900c</txt-record> <txt-record>pdl=application/octet-stream,application/pdf,application/postscript,application/vnd.cups-raster,image/gif,image/jpeg,image/png,image/tiff,image/urf,text/html,text/plain,application/vnd.adobe-reader-postscript,application/vnd.cups-pdf</txt-record> </service> </service-group>
Save and close the file. 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.
Wrapping Up
I hope this tutorial helped you set up a CUPS print server on Ubuntu 20.04, 18.04 and 21.10. 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.
Change it to
Gave an error for me unless I changed it to:
Listen *:631
.Just wanted to let you know that, as soon as I added myself to the lpadmin group, the printer took right off. It’s now working as advertised. Thanks for the tutorial!
this is the most comprehensive instruction that I have ever seen about install and share printer on linux, thanks.
grazie per le preziose e utilissime informazioni
Hey Xiao Guoan, awesome lucid instructions. Thanks. I setup ubuntu as a print share and via Bonjour/IPP connected a linux mint and printed.
Went thru like a breeze.
regards
Maya
Xiao Guoan, thank you for posting this, I needed to get the airprint service off of my desktop as when I VPN into a site / office the other users loose the airprint ability I did notice a message whenever they print now pops up on any IOS device that says the printer name and has a message that says check the printer for errors, then offers a cancel or continue button. It does seem to be printing just fine, is this a normal message?
Kevin, the enclosed link indicates that the “Check the printer for errors” message may have to do with low toner/ink or an empty paper tray. I have run a simple test that verifies this is true for my printers.
https://support.microfocus.com/kb/doc.php?id=7013185
What driver do you use for windows if you choose to use CUPS for a virtual PDF printer instead of a real printer
Generic / Text Only
I followed the instructions and airprint works, however for some reason my iphone for example sees two different printers now, one with the name I gave it in cups and one with ‘Airprint’ in front of the name. And I have to print on the one WITHOUT ‘Airprint’ infront of the name, the other wont work. If I uncheck the ‘Share Printer in Network’ on the cups config website, the one withOUT the name doesnt show up anymore, but I cant print either. And if I disable the avahi-daemon, non of the two show up ofcourse.
This isnt really a problem, just confusing if other people would want to use it, so I was wondering how to get rid of the doubling of the printer showing up, ie remove the one with the additional ‘Airprint’ infront of the printer-name, which cant be used anyways?!
This a brilliant article! Thanks.
Also, I have faced an issue with AirPrint and solved it:
In step 6, the code Xiao provides is tailored to his printer. My HP Laserjet P1102 failed to print with those settings from an iPad. I will tell you how you can find exact settings like “printer-type:0x######” or “pdl:application…” for YOUR printer.
If you have completed step 3 successfully, then install “Service Browser” app from Google Play Store to any android device (I used my smartphone) that is connected to same network (over wifi in this case).
This app allows you to view Bonjour services on your local network.
Open the “Service Browser” app and view details about YOUR specific device.
Then simply change related parameters in the code given in step 6. Save, restart avahi, and done!
I hope this helps you. (There may be an easier and more obvious solution, but this worked for me :))
One is probably the printer shared from CUPS and the other is the driverless printer service created by the Avahi (Airprint) service file. Your iPhone “sees” both on DNS-SD but one requires a driver (CUPS) and the other does not (Avahi).
DO NOT USE the “Share printers…” checkbox from the CUPS Webpage! I tried this and it rewrote and mangled my cupsd.conf file and could no longer access the CUPS web interface remotely, only from the server itself.
To properly fix this, manually edit the /etc/cups/cupsd.conf file. Find the line that says “Browsing On” and set it to “Off”, then save and restart cups: “$sudo systemctl restart cups”.
This disables sharing of CUPS printers over dnssd, if you want to share printers with Windoze, MacOS and other Linux clients, you can still do that through Samba.
Great job linuxBabe, as usual !
Could you give us more details about the cups & printers terminology (ccp://, usb://, .ppd …etc)
Hi,
Anyone know how to force the protocol to ipp or ipps for a client. We upgraded to ubuntu20.04 and the cups clients are not getting all the printers from our print servers (ubuntu stations that share out printers and work for ubuntu18.04 clients).
The 20.04 clients have a partial list with lpstat -v showing as:
device for PRDLRCHK2: implicitclass://PRDLRCHK2/
instead of what were were used to before:
ipp://franklin.local:631/printers/PRX3
The 20.04 clients are creating PPD files so it’s not doing IPP Driverless printing.
Thanks, Eric
Thanks for that awesome article!
Fantastic write up as usual! I look forward to an article for networked printers; a needed update to the deprecated decade-old but promising airprint/cups/bind article here: https://sites.google.com/site/iwastepaper/
😉
Now I get two available printers in the network: HP Laserjet and AirPrint HP Laserjet while physically I have only one. How to merge them and preserve AirPrint and Bonjour availability at the same time?
Does anyone choose size when printing on iOS ? I have no option to choose size paper for printing :((
Followed the article and i could print to the printer over the network connected to Ubuntu from Windows and Android. But having no luck to print from Apple products(iPhone, Macbook, iPad).
AirPrint : created the service as above. Can see the (airprint)printer on iOS and MacOS but cannot print.
On Macbook – See an error “An Error occured while trying to add the selected printer”
iPhone/iPad – “You do not have permission to use this printer”
Samba :
Macbook – “Print held for permission”
Any pointers to help print from Apple devices would be appreciated.
I spend my half an hour reading this blog’s content daily along with a cup of coffee.
To: Xiao Guoan
Re: “Print to Network-Shared AirPrint Printer using CUPS and Avahi” article above.
Thanks so Very Much for this “How To …” tutorial. With these steps, I was able to get a Brother All-In-One MFC model # printer to work with “Kubuntu Server 20.04” – which means “Install/Setup Ubuntu Server 20.04 and then install kubuntu-desktop after Apt Update, Apt Upgrade”. Again Thanks so Very Much !!! HSS
How can I create a virtual printer in Ubuntu
I just did this on Debian 11 (Bullseye), with the change in Step 1 “Listen *:631”, as suggested by Bob in the first response. I didn’t need Step 6, as I tried printing from my iOS 16 iPhone SE 2020 and IT WORKED FLAWLESSLY!!
Now, I’m going to try it on a Raspberry Pi 3B+ running Raspbian. Not expecting much, because Raspibian has some strangeness to it…
Thank you SO MUCH Xiao Guoan! You da man!!!
On iOS, iPadOS, and openSUSE Tumbleweed, I could see the printer, but I every time I attempted to print, I would get an error message.
Kubuntu has my printer attached to the USB port. Running openSUSE Tumbleweed on the second computer. I have an iPad and iPhone. Some testing from openSUSE tipped me off to why the iPad refused to print, despite being able to “see” the printer.
In the terminal on Kubuntu, I had to type in the following commands:
cupsctl –share-printers
cupsctl –share-printers –remote-any
lpadmin -p printer -o printer-is-shared=true
After adding those commands, I could printer remotely over the network from openSUSE Tumbleweed, iOS, and iPadOS.
Thank you for these detailed instructions. My printer is connected to my Linux desktop via USB. I did everything here (except the SAMBA part since we have no Windows machines) and now my linux laptop can see and use the printer. However my wife’s MacBook running MacOS 11.7.6 cannot see the printer. Neither can her iPhone. I would love to know how to debug this. Both Linux machines are running Ubuntu 23.04 and everything is on the same local network via WiFi.
Unfortunately I followed your steps to a T, but using IPP and Windows 10 Pro, the printer is never shown as available. Going the Samba route yields the same result. I can reach the server via IP address in Windows Explorer, but there’s nothing available to select. Any ideas?
Hello! I’m at work browsing your blog from my new iphone 3gs!
Just wanted to say I love reading through your blog and look forward to all your posts!
Carry on the superb work!
in this sentence near the end, talking about updating the avahi service configs, the sentence: “We need to create a .service file in the /etc/avahi/services/ directory for the printer with a Python script with the following command.” baffles me…where is the Python script? what am i missing?
Great article and has held well against the test of time.
I’m ok in the windows space and a bit of a noob in Linux. Was looking to get Airprint working for an Ipad. Also I’m on Debian rather than Ubuntu (on a beagleboard black to be precise) and using a HP CM1312NFI printer over the network.
For my particular instance, to be able to add a printer through the web interface to I had to change the /etc/cups/cupsd.conf
In replaced “Require user @SYSTEM” with “Require valid-user”
Then the same again in and for later convenience.
Avahi appeared to be already installed and as I’d selected the share option in the CUPS web interface when I added the printer, there was no need to create the .services file.
Xiao, thank you very much for the article.
Some of my content was erased.
The sections where I made changes in /etc/cups/cupsd.conf were: Location /admin/conf, Location /admin/log and Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add…
THANK YOU, I LOVE IT!!!!
It looks like MacOS and maybe Windows have all been recently patched such that CUPs will no longer work because of stricter enforcement of SSL certificate handling on the print server.
for wireless printers you can also use:
“sudo lpinfo –include-schemes dnssd -v”
possible result:
“network dnssd://EPSON%20XP-4150%20Series._ipp._tcp.local/?uuid=cfe92100-67c4-11d4-a45f-a4d73c6344e6”
or “arp-scan –localnet”
possible result: (ip4, ip6, device-name)
192.168.0.101 a4:d7:3c:63:44:e6 Seiko Epson Corporation
…