Print Server


According to the Raspberry Pi Foundation, the Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse[1].  In 2012, the Foundation launched Raspberry Pi, a single-board computer designed to teach programming skills, build hardware projects, do home automation, and explore industrial applications of computer technology. An economical computer – $55.00 or less – it runs Linux (a computer operating system) and provides general-purpose input and output (GPIO) pins that allow the user to control electronic components for physical computing and exploring the Internet of Things (IoT).  The operating system for all Raspberry Pi products is Linux. Linux is an open-source operating system that interfaces between the computer’s hardware and software programs.  It is a very versatile board with application in several areas including file servers, retro gaming and print servers. In this article, we will explorer it’s use as a print server.

When we want to connect multiple computers to a printer or we want to share a printer on a network, then we usually need a device referred to as a print server. A print server can be just a computer with a number of printers shared on the network, but it can be a dedicated device that is networked and also connects to a number of printers. The server acts as the interface between computer users requiring a printing service and the printers themselves. Sometimes the server is a feature or a service on another device such as a router or wireless access point. This is a good idea but does have its disadvantages, least of all the fact that the print server function is just another function on the router and it may not provide the same level of service as dedicated print servers do. Most servers that provide facilities for print sharing usually have a management interface that can normally be accessed over the network. This interface will sometimes allow the administrator of the server to set up user permissions and to set up any specific operation of the device. A client can just use a particular printer when it has been approved using some verification technique. At the point when various printers are being used, the server might be modified so that a few clients can just use specific printers whilst others may have consent to get to all printers. 

Before a document can printed, the print server and your computer’s operating system must locate the printer you want to use, establish a network communication path to it, package your document into a data format the printer can directly understand, send the formatted data to the printer and monitor the progress of the printer while it prints your document. Finally, it reports to you whether the print process was successful or not. The printer drivers installed on your computer and network printing protocols like IPP ( Internet Printing Protocol ) and LPR ( Line Printer Remote protocol ) handle the complicated, low-level details for you.

According to WIkipedia’s Internet Printing Protocol, Internet Printing Protocol ( IPP ) is a specialized Internet protocol for communication between client device and printers or print servers<a href=”#anchor2″>[2]</a>.  IPP uses HTTP as its transport protocol. Each IPP request is a HTTP POST with a binary IPP message and print file, if any, in the request message body. The corresponding IPP response is returned in the POST response. HTTP connections can be unencrypted, upgraded to TLS encryption using an HTTP OPTIONS request, or encrypted immediately (HTTPS). HTTP POST requests can also be authenticated using any of the usual HTTP mechanisms.  Printers are identified using Universal Resource Identifiers (“URIs”) with the “ipp” or “ipps” scheme. Print Jobs are identified using the Printer’s URI and a Job number that is unique to that Printer.  In order to use IPP in the Raspberry Pi, we will have to use CUPS ( Common UNIX Printing System ).

The Common Unix Printing System, also known as CUPS, is a system designed for Unix and Apple’s OS X that allows a computer to act as a print server. A computer running CUPS can accept print jobs from other computers and route them to local and network printers using the Internet Printing Protocol, or IPP.  First released in June 1999, CUPS includes a print spooler, scheduler, a filter to convert data to a format understood by the printer, and a backend processor for routing print jobs.  CUPS consists of a print spooler and scheduler, a filter system that converts the print data to a format that the printer will understand, and a backend system that sends this data to the print device. CUPS uses the Internet Printing Protocol (IPP) as the basis for managing print jobs and queues. It also provides the traditional command line interfaces for the System V and Berkeley print systems, and provides support for the Berkeley print system’s Line Printer Daemon protocol and limited support for the server message block (SMB) protocol. System administrators can configure the device drivers which CUPS supplies by editing text files in Adobe’s PostScript Printer Description (PPD) format.  CUPS is free software, provided under the Apache License<a href=”#anchor3″>[3]</a>.

To set up our print server, we need an Operating System that will run on our Raspberry Pi.  We will be using Rasbian in this article.  Installing Raspbian on the Raspberry Pi is pretty straightforward. We’ll be downloading Raspbian and writing the disc image to a microSD card, then booting the Raspberry Pi to that microSD card. For this project, you’ll need a microSD card (go with at least 8 GB), a computer with a slot for it, and, of course, a Raspberry Pi and basic peripherals (a mouse, keyboard, screen, and power source). First, download the Raspbian disc image. You can find the latest version of Raspbian on the Raspberry Pi Foundations website <a href=”https://www.raspberrypi.com/software/operating-systems/” target=”_blank”>here</a>.  The Raspbian disc image is compressed, so you’ll need to unzip it. The file uses the ZIP64 format, so depending on how current your built-in utilities are, you need to use certain programs to unzip it like <a href=”https://www.7-zip.org” target=”_blank”>7-zip</a>.  Unzip the image file that was downloaded and note the location of the unzipped *.img file.

Once the file is unzipped,  we will need an application to write the file to a microSD card.  <a href=”https://ames-pc.com/geek/blogs/blog.html?issue=1949″ target=”_blank”>There are several different applications available for free use, which allows you to flash ISO images to SD cards</a>. In this tutorial, we will use Etcher.  Etcher is a free and open-source utility for flashing images to SD cards & USB drives and supports Windows, macOS, and Linux.  You can download the most recent Etcher for your operating system from <a href=”https://www.balena.io/etcher/#download” target=”_blank”>Etcher’s download page</a>.  Once downloaded and installed,  insert the SD card into your SD card drive and Launch Etcher.  Click on the Select image button and locate the Raspbian files that you noted from the unzipping program you used.  Etcher will auto-select the SD card if only one drive is present. Otherwise, if more than one SD card or USB stick are attached, make sure you have selected the correct drive before flashing the image.  Be very careful in this step because Etcher will overwrite any files on the drive you select. Click on the <b>Flash</b> button, and the flashing process will start. Etcher will show a progress bar and ETA while flashing the image. The process may take several minutes, depending on the size of the ISO file and the card speed.  After the writing complete, safely remove the SD Card from the reader.

We need to set up our raspberry pi before we set up our print server. We can either do a normal setup by connecting a monitor, keyboard and mouse to the Raspberry Pi or a headless setup using ssh or vnc. For this article, we will perform a normal setup.  First,  we will connect the Raspberry Pi to a monitor, keyboard, mouse and network cable. Plug the SD card to the Pi.  Turn on the power supply and wait until the OS boots.  Once the Raspberry Pi is booted up,  we will need to make sure that our Raspberry Pi has all the latest updates to the OS. To do this, open a terminal window and type the following 2 commands one after another

<br>

<code>

  <pre>

    Sudo apt-get update

    sudo apt-get upgrade

  </pre>

</code>

<br><br>

After the upgrade is finished,  we will need to reboot the pi.  We can do it from the GUI window or from the terminal.  To reboot from the terminal,  type in <b>sudo reboot</b> in the terminal window.

<br><br>

We can now set up our printer server software CUPS on the Pi. The Raspberry Pi running CUPS can accept jobs from client devices, process them and pass it on to the appropriate printer to print.  Before Setting up CUPS,  we need to make a few system tweaks so that we can use the Pi as a server on the network. We need to set the DHCP client to use a static IP address.  The system is set by default to <b>DHCP</b> where the Raspberry Pi can pick any available network address, which would make it hard to know how to connect to the Raspberry Pi over the network.  We start by editing the DHCP config file by opening the terminal windows and typing in the following:

<br>

<code>

  <pre>

    Sudo nano /etc/dhcpcd.conf

  </pre>

</code>

<br><br>

Scroll to the bottom of the file and add one, or both of the following snippets, depending on whether you want to set a static IP address for a wired connection ( eth0 ) or a wireless connection ( wlan0 ).  In this tutorial,  we will be setting the wired connection ( eth0 ) for a static ip.  Enter the following under <b>eth0</b>

<br>

<code>

  <pre>

    static ip_address=192.168.0.10/24

    static routers=192.168.0.1

    static domain_name_servers=192.168.0.1

  </pre>

</code>

<br><br>

Change <b>static ip_address</b> to the IP address that you want to set your device to. Make sure you keep the <b>/24</b> for your subnet mask.  Change <b>staic routers</b> to the IP address of your gateway which is probably the IP address or your router. Change the <b>static domain_name_server</b> to  the IP address of your DNS which is probably the IP address of your router. You can add multiple IP addresses here separated with a single space.  Once the file has been edited,  save the file by entering <b> Ctrl + X</b> then press <b>Y</b> and <b>Enter</b>.  Again, reboot the pi by typing <b>sudo reboot</b> in the terminal or using the GUI.

Next, we need to install CUPS. This will take some time but will install CUPS and other dependencies like samba, perl and several other software or libraries.  To install CUPS,  open up a terminal window and type in the following>

 <br>

<code>

  <pre>

    sudo apt-get install cups

  </pre>

</code>

<br><br> 

After CUPS is installed,  we will need to make some changes to the configuration.  To make the changes,  type <b>sudo nano /etc/cups/cupsd.conf</b> in the terminal window.  Change/add the following lines to the configuration file. These changes will allow us to interact with CUPS panels.  We will also enable the CUPS web interface here.

<br>

<code>

  <pre>

# listen on all interfaces

#Listen localhost:631

# Restrict access to the server…

<Location />

  Order allow,deny

  Allow @Local

</Location>

# Restrict access to the admin pages…

<Location /admin>

  Order allow,deny

  Allow @Local

</Location>

# Restrict access to configuration files…

<Location /admin/conf>

  AuthType Default

  Require user @SYSTEM

  Order allow,deny

  Allow @Local

</Location>

  </pre>

</code> 

<br><br>

Again,  save the file by entering <b> Ctrl + X</b> then press <b>Y</b> and <b>Enter</b>.

Next we add the Pi user to the lpadmin group. This gives the Raspberry Pi the ability to perform administrative functions of CUPS without necessarily being a super user.  We do this by opening up the terminal windows and typing in the following: <b>sudo usermod -a -G lpadmin pi</b>.  We now need to make sure that CUPS is accessible across the entire network by entering the following command: <b>sudo cupsctl –remote-any</b>.  Next,  we need to restart CUPS to effect the changes by entering <b>sudo /etc/init.d/cups restart</b> 

Next,  we need to install Samba. Samba is the standard Windows interoperability suite of programs for Linux and Unix. It will allow the Windows system to communicate with our CUPS server running on the Pi, and will allow us to send print commands from Windows.  To install Samba,  type in the following in the terminal window, <b>sudo apt-get install samba</b>. We now edit the samba configuration to allow guests to print.  To edit the samba configuration,  we need to type the following in the terminal window, <b>sudo nano /etc/samba/smb.conf</b>.  Once the configuration file is open,  go to the print section and change the <b>guest ok = no</b> to <b>guest ok = yes</b>.  Next,  go to the printer driver section and change <b>read only = yes</b> to <b>read only = no</b>.  Again,  save the file by entering <b> Ctrl + X</b> then press <b>Y</b> and <b>Enter</b>.  Restart Samba for the changes to take effect by entering <b>sudo /etc/init.d/smbd restart</b>.

This is the last step to do. From your PC, connect to the same network as your Pi. Open a web browser and go to the CUPS homepage by entering your Raspberry Pi’s IP address followed by <b>:631</b> which is the port address on which CUPS is communicating. It may be different in case you changed the port. The browser may show a warning “Connection not secure”, click <b>Proceed Anyway</b>.  To get the Raspberry Pi’s IP address, you can run the command <b>hostname -I</b> in a terminal window from your Pi.  In the browser window,  go to the Administration page and click Add Printer. Make sure that your printer is switched on and connected to your Pi via USB. Follow the prompts and set up the printer. Before the final step, ensure that you check the <b>share this printer</b> checkbox. Finally, you can print a test page on Printers page to verify if everything works.

<p id=”anchor1″>[1]<a href=”https://www.raspberrypi.org/help/what-%20is-a-raspberry-pi/=”_blank”>  https://www.raspberrypi.org/help/what-%20is-a-raspberry-pi/</a></p>

<p id=”anchor2″>[2]<a href=”https://en.wikipedia.org/wiki/Internet_Printing_Protocol” target=”_blank”>  https://en.wikipedia.org/wiki/Internet_Printing_Protocol</a>    “Internet Printing Protocol”</p>

<p id=”anchor3″>[3]<a href=”https://www.cups.org/doc/license.html”_blank”>  https://www.cups.org/doc/license.html</a></p>