Print server¶
Exercise print-server-annex.pdf · PDF
Twelve people, one printer, 13:55 on a Friday. Everybody prints in the same minute. Why don't the pages of twelve documents come out mixed together?
Because the documents wait in order, and somebody keeps that order. And when one 300-page document blocks everybody else, somebody must be able to take it out. That somebody is a service on the server, and on this page you install it, share it, and drive its queue by hand.
What you will learn
- What a print server adds to a printer: one queue, one place to manage it
- Name the pieces: CUPS, IPP, port 631, job, queue, spooler
- Create a print queue on the server and share it on the network
- Print to it from a client, and find the job
- Pause a queue, list the waiting jobs and cancel one
- Why "the printer is broken" is usually not the printer
One printer, twelve people: the queue¶
Think of the ticket machine at the bakery counter. Each customer takes a number and waits; the baker serves them in order. Nobody pushes, and if someone with a huge order is holding everybody up, the manager can move them aside.
- A document sent to print is a job (a customer with a ticket).
- Jobs wait in a queue (the line of numbers).
- The program that keeps the queue and feeds the printer is the spooler (the baker who calls the next number).
There are three ways to reach a printer:
| How | The problem | |
|---|---|---|
| Local | USB cable to one PC | One user |
| Network printer, direct | Each PC talks to the printer itself | Twelve PCs to configure; nobody sees the whole queue |
| Print server | PCs send to the server; the server sends to the printer | One more service to look after, but one queue, one place for permissions, one log of who printed what |
A print server is a service that receives print jobs from the clients, keeps them in a queue and sends them to the printer.
flowchart LR
C1["<b>deb-lab</b>"] -->|"job"| Q
C2["<b>win11</b>"] -->|"job"| Q
C3["<b>marta's laptop</b>"] -->|"job"| Q
subgraph SRV ["ubu-srv: the print server"]
Q["<b>queue office-pdf</b><br>jobs wait in order<br>(the bakery tickets)"]
end
Q -->|"one job at a time"| P["<b>Printer</b><br>today: a PDF file"]
CUPS and IPP¶
On Linux and macOS the spooler is CUPS. Michael Sweet started writing it in 1997 at his small company, Easy Software Products; the first public beta came out on 14 May 1999. Apple adopted it for macOS in 2002 and bought it in 2007; today the OpenPrinting project maintains it.
CUPS speaks IPP, the Internet Printing Protocol, on TCP port 631. So do modern printers themselves, which is why a new printer usually works with no driver at all.
Today's printer is virtual: a queue that turns every job into a PDF file. Everything is the same as with paper except the last metre.
Install CUPS on the server¶
lpstat -r should say scheduler is running. Now look at the ss line: CUPS listens on 127.0.0.1:631 and [::1]:631, localhost only. Remember Clients, servers and shared resources: right now deb-lab cannot reach it.
The installation may already create a queue called PDF. That is harmless; you will make your own.
Create a queue and print¶
One command in three lines (the \ at the end of a line means "it continues"):
sudo lpadmin -p office-pdf -E -v cups-pdf:/ \
-m lsb/usr/cups-pdf/CUPS-PDF_opt.ppd \
-D "Tramuntana office printer" -L "Palma office"
| Option | Meaning |
|---|---|
-p office-pdf |
The queue's name |
-E |
Enable it, so it accepts jobs |
-v cups-pdf:/ |
Where the jobs go: here, the PDF maker |
-m ...ppd |
The model file (the driver) |
-D, -L |
Description and location, for humans |
CUPS answers with an honest warning: Printer drivers are deprecated and will stop working in a future version of CUPS. Drivers are on their way out because of IPP; our PDF printer still needs one.
$ sudo lpadmin -d office-pdf
$ lpstat -p -d
printer office-pdf is idle. enabled since Mon Oct 5 21:01:03 2026
system default destination: office-pdf
$ echo "Invoice 2027-041" > invoice.txt
$ lp invoice.txt
request id is office-pdf-1 (1 file(s))
lpadmin -d makes it the default queue; lp sends a job, and CUPS gives it a request id: the bakery ticket. The PDF appears in ~/PDF/ of the user who printed.
Share the queue¶
sudo cupsctl --share-printers
sudo lpadmin -p office-pdf -o printer-is-shared=true
sudo ss -tlnp | grep 631
Now CUPS listens on every address (0.0.0.0:631 or *:631). cupsctl rewrote /etc/cups/cupsd.conf for you: Listen localhost:631 became Port 631, and machines of the local network were allowed. It does not open the printer to the whole Internet, and the router's firewall is still there.
Print from the client¶
On deb-lab (if lp is missing, install cups-client):
$ lpstat -h ubu-srv -p -d
printer office-pdf is idle. enabled since Mon Oct 5 20:55:59 2026
system default destination: office-pdf
$ echo "hello from deb-lab" > hello.txt
$ lp -h ubu-srv -d office-pdf hello.txt
request id is office-pdf-2 (1 file(s))
-h ubu-srv means "ask the CUPS of that host". Where is the PDF? On the server: in ~/PDF/ if a user with the same name exists there, otherwise in /var/spool/cups-pdf/ANONYMOUS/. With paper, it would come out of the printer; the client keeps nothing.
GNOME on deb-lab may even show office-pdf in Settings → Printers by itself: shared CUPS queues announce themselves on the local network.
Manage the queue¶
Pause the queue on the server, send three jobs from the client, and look:
sudo cupsdisable office-pdf # server
for i in 1 2 3; do lp -h ubu-srv -d office-pdf hello.txt; done # client
lpstat -o # server
$ lpstat -p
printer office-pdf disabled since Mon Oct 5 21:01:03 2026 -
Paused
$ lpstat -o
office-pdf-1 marta 1024 Mon Oct 5 21:01:03 2026
office-pdf-3 root 1024 Mon Oct 5 21:01:03 2026
A paused queue still accepts jobs: it only stops sending them to the printer. Each line of lpstat -o is a waiting job: its id, who sent it, its size and when. Cancel one, then restart the queue:
The waiting jobs come out in order, and lpstat -W completed -o lists the finished ones. The cancelled job never becomes a PDF.
| Command | What it does |
|---|---|
lpstat -p |
State of each queue: idle, printing, paused |
lpstat -o |
The jobs waiting in the queues |
lp -d queue file |
Send a job |
cancel job-id |
Remove a job from the queue |
cupsdisable / cupsenable |
Pause / restart a queue |
Careful: the printer is not broken
"My document does not come out." Most of the time the printer is fine and the queue is stopped, or a job in front of yours is stuck. Look at the queue first (lpstat -p, lpstat -o), then at the printer. And cancelling on your own PC does not help: the job lives in the server's queue.
Key takeaways¶
- A print server gives one queue, one place for permissions and one log for a shared printer.
- A job waits in a queue; the spooler feeds the printer. On Linux and macOS it is CUPS (Michael Sweet, 1997–1999).
- CUPS speaks IPP on TCP 631; modern printers speak IPP too, so they often need no driver.
lpadmincreates a queue,cupsctl --share-printersopens it to the local network (by default it is localhost only),lp -h serverprints from a client.- A paused queue keeps accepting jobs. Check the queue with
lpstatbefore blaming the printer.
Quick check¶
1. Which protocol and port does CUPS use?
- IPP, port 631
- SMB, port 445
- SSH, port 22
- NFS, port 2049
CUPS speaks the Internet Printing Protocol on TCP 631, the same protocol modern printers speak themselves.
2. A queue is paused and you send a job to it. What happens?
- It is accepted and waits in the queue
- It is refused with an error message
- It prints at once, skipping the pause
- It is deleted without telling anyone
A paused queue keeps accepting jobs and only stops feeding the printer. After cupsenable, the waiting jobs come out in order.
3. Right after installing CUPS, who can send jobs to it?
- Only the server itself
- Every machine on the LAN
- Every machine on the Internet
- Only the Windows clients
By default CUPS listens on 127.0.0.1:631: localhost only. cupsctl --share-printers makes it listen on every address and allows the local network.
4. A user says “my document does not print”. What do you look at first?
- The queue, with lpstat -p and lpstat -o
- The printer's power cable
- The user's password
- The file /etc/exports
Most of the time the printer is fine and the queue is paused or a job is stuck. lpstat -p shows the queue's state and lpstat -o the waiting jobs.
5. You print from deb-lab with lp -h ubu-srv -d office-pdf hello.txt. Where does the PDF appear?
- On the server, which runs the queue
- On deb-lab, in the folder where you typed lp
- On both machines, one copy each
- Nowhere, a client cannot print to a server
The job travels to the server's queue and the server feeds the printer, here the PDF maker. The client keeps nothing, just as no paper comes out of your PC.
6. What does a print server add compared with every PC talking directly to a network printer?
- One queue and one place to manage permissions and logs
- Faster printing, because the server has more RAM
- Colour printing on black-and-white printers
- Printing without any network connection
With direct printing, twelve PCs must be configured and nobody sees the whole queue. A print server keeps one queue, one place for permissions and one log of who printed what.
7. A 300-page job is blocking the office printer at 13:55. Select the two that are true.
- lpstat -o on the server shows the job and its id
- cancel with that id removes it from the server's queue
- Cancelling it on the sender's PC removes it from the server
- Restarting the printer always deletes the whole queue
The job lives in the server's queue. Find its id with lpstat -o, then cancel it there; the jobs behind it move on in order.
Count what is on your server now: SSH, Samba, NFS, CUPS, four services side by side, sharing the same system. What if two of them need different versions of the same library? Next, each service gets its own sealed box: Containers.