Turn your Raspberry Pi into a print server

Ames Computer Geek Corner News Turn your Raspberry Pi into a print server NYC New York City North Bergen County

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[2]. 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 tu 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 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[3].

To setup 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 here. 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 7-zip. Unzip the image file that was downloaded and note the location of the unzipped *.img file.

Once the file is unzipped, we wil need an application to write the file to a microSD card. There are several different applications available for free use, which allows you to flash ISO images to SD cards. 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 Etcher's download page. 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 autoselect 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 Flash 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 setup our raspberry pi before we setup our print server. We can either do a normal setup by connecting monitor, keyboard and mouse the Raspberry Pi or a headless setup using ssh or vnc. For this article, we will perform a normal setup. First, we will onnect 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

    Sudo apt-get update
    sudo apt-get upgrade

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 sudo reboot in the terminal window.

We can now setup 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 DHCP 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:
    Sudo nano /etc/dhcpcd.conf

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 static ip. Enter the following under eth0
    static ip_address=
    static routers=
    static domain_name_servers=

Change static ip_address to the IP address that you want to set your device to. Make sure you keep the /24 for your subnet mask. Change staic routers to the IP address of your gateway which is probably the IP address or your router. Change the static domain_name_server 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 Ctrl + X then press Y and Enter. Again, reboot the pi by typing sudo reboot 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 termihal window and type in the following>

    sudo apt-get install cups

After CUPS is installed, we will need to make some changes to the configuration. To make the changes, type sudo nano /etc/cups/cupsd.conf 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.
# listen on all interfaces
#Listen localhost:631
# Restrict access to the server...

  Order allow,deny
  Allow @Local

# Restrict access to the admin pages...

  Order allow,deny
  Allow @Local

# Restrict access to configuration files...

  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow @Local


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

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: sudo usermod -a -G lpadmin pi. We now need to make sure that CUPS is accessible across entire network by entering the following command: sudo cupsctl --remote-any. Next, we need to restart CUPS to effect the changes by entering sudo /etc/init.d/cups restart

Next, we need to install Samba. Samba is the standard Windows interoperability suite of programs for Linux and Unix. It will allow 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, sudo apt-get install samba. We know edit the samba configuration to allow guests to print. To edit the samba configuration, we need to type the following in the terminal window, sudo nano /etc/samba/smb.conf. Once the configuration file is open, go to the print section and change the guest ok = no to guest ok = yes. Next, go to the printer driver section and change read only = yes to read only = no. Again, save the file by entering Ctrl + X then press Y and Enter. Restart Samba for the changes to take effect by entering sudo /etc/init.d/smbd restart.