Outils pour utilisateurs

Outils du site


issue172:tutoriel2

Ceci est une ancienne révision du document !


This will be a short note on how to connect a printer to your network using a Raspberry Pi. It is not meant to be a full tutorial, but rather some quick notes that may help you, the reader, if you find yourself in the same position I was.

I happen to be the proud owner of a HP Laserjet 2100 printer. This is a now ancient 1999-era piece of equipment that prints a tad more slowly than modern machines. On the positive side of things, however, its 1200 dpi resolution is more than satisfactory for office tasks even by today’s standards. In a time of need, it was readily available in my back room, complete with a spare toner cartridge, and fired right up immediately after about seven years in storage. Also, I am not disposed to spend cash on a new piece of kit unless it outperforms my old stuff considerably, or to go through the hassle of acquiring, transporting and setting up a new printer.

The only feature I do miss on modern printers is network access. Although the Laserjet 2100 is a fine printer, its connectivity is limited to a single parallel port. Remember back when? I am sure older readers will, but youngsters may struggle with the concept. Anyway, the printer came with a parallel port-to-USB converter cable that works very well. I also had a spare Raspberry Pi lying around, and so was all set to plug the hardware in and build myself a 1999/2021 vintage network printer. The converter cable (black) went into the printer’s parallel port on one end, and into one of the RPi’s USB sockets on the other. I used a physical Ethernet cable (red) to connect the RPi to my home router, and a spare USB cable and telephone charger (white) to power the RPi. That was the hardware side of things taken care of.

The operating system I already had on the SD card in my RPi was Raspberry Pi OS, previously known as Raspbian. Based on Debian “Buster”, it is sufficiently similar to Ubuntu Server that most commands are identical, up to and including useful commands to install software such as apt, aptitude, and so forth. I will not delve here into setting up the network on the RPi since such matters are very well explained in the official documentation (https://www.raspberrypi.org/documentation/). In particular, I would like to point you to the page on setting up Wireless networking, which may be of interest if using a RPi version 3 or 4. These have a built-in WiFi chip, and can connect directly to your access point, thus saving some cabling (https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md). Since I was using a similar but older version 2, my precise specs and setup were:

Now, to set up printing: from the software point of view the obvious candidate is the Common UNIX Printing System, or CUPS. This can contain the print server software itself, printer drivers and a Web server to access and configure our printers from our main computer. It also implements the Internet Printing Protocol (IPP), a very simple and robust protocol that - in my opinion, at least - is far superior to Microsoft’s SMB/CIFS printer sharing protocols as regards speed and dependability. Moreover, most modern network printers use this protocol, and, as a consequence, most operating systems also support it. The protocol can also be queried directly using a standard web browser, which helps a lot for configuration.

I installed CUPS (as root) using command:

aptitude install cups cups-core-drivers

Other software packages, including cups-daemon and printer-driver-gutenprint, were also installed automatically. The CUPS daemon is started, and set up to start automatically with sysctl. As a security feature, however, it is initially configured to listen on only the localhost interface (address 127.0.0.1):

netstat -l | grep ipp

tcp 0 0 localhost:ipp 0.0.0.0:* LISTEN

tcp6 0 0 localhost:ipp [::]:* LISTEN

To change this, we need to edit file /etc/cups/cupd.conf, and change the line reading:

Listen localhost:631

to:

Listen 0.0.0.0:631

To allow configuration of the server from other computers in our network, I also needed to add several Allow stanzas further down in the same file:

<Location /> Order allow,deny Allow localhost Allow from 192.168.* </Location>

<Location /admin> Order allow,deny Allow localhost Allow from 192.168.* </Location>

As shown, these are correct – assuming we are using IP addresses from block 192.168/16 on our local network; otherwise we would need to adapt to suit. It does make sense to open up administration to other machines on our local network, but not make our server accessible from further away. Once this is done and the file saved, we can restart CUPS using command:

systemctl restart cups

We can now connect to our print server from any web browser on our network, using the IP address of the RPi on our network and port 631. For instance, if our RPi has IP address 192.168.1.142, we would use: http://192.168.1.142:631 (shown top right)

When adding a new printer, it is possible that our browser will complain of a bad certificate when switching to the HTTPS protocol. We can safely continue by accepting this certificate and adding a security exception. We may also need to authenticate. I logged in as the main user on the RPi. By default, this is username “pi” and password “raspberry”, though it would perhaps be best to change the password at the very least.

I then went to the CUPS “Add Printer” (shown below) option, where the Laserjet had been recognized and was offered for configuration.

Let us remember to actually share this printer, by checking the box (shown next page, top right).

On the client side of things, most modern Linux systems will automatically detect the presence of our new printer server, and automagically configure our new printer for us. In my case, on a Kubuntu 20.04, the new printer appeared immediately:

If this is not the case, simply go to the configuration panel and manually add the printer which should have been discovered on the network. For instance, on a recent Manjaro:

The great thing about CUPS is that it is a universal piece of software. The very same software has actually been baked into Apple’s Mac OS. Thus, the network printers advertised by the RPi over “dnssd” are readily recognized by the Mac as having been announced over “Bonjour”.

The end result is identical, and the new printer can be configured with ease on Mac OS. No fiddling about with printer drivers was needed; the Mac and CUPS figured it out between them and within a minute I was printing away wildly. Note the Gutenprint drivers in use - these are the same as installed on a Linux CUPS implementation.

Things may be a tad different from a Windows machine for users who are accustomed to configuring printers over Windows printer sharing protocol (SMB/CIFS). In this case, the printer server on the RPi is communicating over IPP, so just browsing the local network in our file explorer on the Windows machine will not find it.

Instead, we need to get over to the Control Panel (or Settings, or whatever else it is called these days) and select “Devices (Bluetooth, printers, mouse)”, then “Add a printer or scanner”. This will search for our new printer server, but is just as likely to find the neighbor’s WiFi-connected ink-jet instead of our own RPi server. Simply choose “The printer that I want isn’t listed”, then “Add a printer using a TCP/IP address or hostname”. In my case, I entered (please note the :631 port number): http://192.168.1.142:631/printers/HP_Laserjet_2100_Series

After jumping through a couple more hoops - such as telling Windows to use a printer driver meant for a completely distinct Postscript printer (the “HP Color Laserjet 2500 PS Class Driver”) - I got my new printer set up and working.

For more details to set up IPP printers on Windows, there is a good tutorial on The Zedt: https://zedt.eu/tech/windows/installing-an-ipp-printer-in-windows-10/ .

The end result was that, with a Raspberry Pi version 2 and a 20-year-old laser printer, I had a working, printing networked laser using the CUPS software. From plugging in the hardware, installing cups, to getting the system fully working on Linux and Apple machines on my local network, the complete process took about half an hour. Convincing my lone Windows laptop to print took a further hour of fiddling and searching for tutorials on the Web, which is probably par for the course.

Extending my server would be a simple matter of physically connecting another printer to the RPi, and configuring CUPS through the web interface. As a side note, most professional-grade printers of major brands tend not to be too complex to set up, especially when they are compatible with the Postscript language. Printers originally meant for “home use” may be more challenging to set up, for instance by requiring the use of specific drivers or even proprietary software kits and firmware. Some previous research may be a good idea to ensure compatibility between the printer and Linux before proceeding.

issue172/tutoriel2.1630309290.txt.gz · Dernière modification : 2021/08/30 09:41 de auntiee