Raspberry Pi Print-Server Part 2 – server and client setup

For this standalone printserver project based on Raspberry Pi, I’m going to use my own setup with CUPS + IPP as an example to print documents (SAMBA setup is on the bottom of this text, providing an example if file–serving is also an option on the same server.)

In this article, I’ll assume you’re running Raspbian on your Raspberry Pi system, but similar instructions will work for other linux / rpi distros.

Step 1 – Initial setup

We should assign the rPi a static IP address, either through the router or on the rPi. The fixed IP address must not be an address assigned by the router to other DHCP clients. If the router residing at 192.168.0.1 distributes an address range of 192.168.0.100 to 192.168.0.254 to DHCP clients on the network, edit the file /etc/network/interfaces:

#/etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.0.240
netmask 255.255.255.0
gateway 192.168.0.1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

For the system to resolve common URLs to Internet addresses, we must specify a DNS name server. In some cases, the router might act as a DNS server.

Edit /etc/resolv.conf and add
nameserver 192.168.0.1

For the other basic system settings, call up sudo raspi-config (i.e. like expanding the filesystem, renaming the rPi, and SSH). Putty is great to use to remote config the server from a Windows node.

Then run
sudo apt-get update && sudo apt-get upgrade
to update the software on your rPi system.

And changing the default password from ‘raspberry’ with
passwd

Step 2 – Installing CUPS

sudo apt-get install cups (if its not present)

After the install, CUPS runs as a system service and provides a management interface on the local system.

Next we add the pi user to the lpadmin group, so it can access the administrative functions of CUPS:
sudo usermod -a -G lpadmin pi
sudo service cups restart

Installing our printer happens through the CUPS web interface Administration menu, ‘Add Printer’ button, at https://192.168.0.240:631/admin from a client. We can use the pi user account set up previously. If the printer itself (here, the Canon MG5150) is connected via USB and turned on, CUPS automatically detects and displays it. Select the Canon MG5150, and then press Next. We can now enter a description for the device and share the printer on the network. In the next step, select the top driver Canon MG5100 – CUPS+ Gutenprint v5.2.10 (en). A click on Add printer takes us to the default settings, where we typically do not need to change anything.

If all goes well, the printer is then available via CUPS. A click on the Canon_MG5150 link shows us the printer, and we can select Print test page in the upper left selection to check to see whether the device works as desired.

(On my setup I had to specify the source of the paper to ‘cassette’ at the bottom of the printer, as it was trying to feed paper from the backloader (for those thick photopapers) with ‘Automatic Paper Source Switching’, and the printer was cryptically telling me that there was no paper. Logically enough!)

Restart CUPS: sudo service cups restart

cups001

cups006

cups005

cups004

cups003

cups002

Printing from Linux

The client should automatically find the printer because we enabled the appropriate services for the local network in the previous step. If not, we need to setup CUPS locally (http://127.0.0.1:631/admin), push “Add Printer” and point it to our print-server:
http://HOST:631/printers/Printer_Name
In my case that was http://192.168.0.240:631/printers/Canon_MG5100

The service might need to be restarted sudo service cups start

After we’ve completed the steps in Print Add wizard, make sure to run a test print to ensure the printer is actually printing. Same goes for every client.

CUPS can be configured to run without a local spooler and send all jobs to a single server. However, if that server goes down then all printing will be disabled. The default server is normally the local system (“localhost”). To override the default server create a file named /etc/cups/client.conf with a line as follows:
ServerName server

The server name can be the hostname or IP address of the default server. If the server is not using the default IPP port (631), you can add the port number at the end like this:
ServerName server:port

Printing from Windows

Make sure IPP client is turned on:
Go into the Control Panel -> Programs, select “Turn Windows features on or off”
In the features dialog, scroll down to “Print and Document Services”. Check “Internet Printing Client”. Reboot.

Or through the command line with elevated rights:
To get the feature names: dism /online /get-features
To enable IPP: dism /online /enable-feature /featurename:Printing-Foundation-InternetPrinting-Client

In printer manager, click Add a printer, then Add a network, wireless or Bluetooth printer
Skip detection, go Next
The next dialog, “Type a printer hostname or IP address”, in the middle box, where it says Hostname or IP address, use the following: http://HOST:631/printers/Printer_Name
Point the setup to the drivers, if promted, and reboot.

201608_win000

(If that doesn’t work, or the client is running on win8:
Navigate to HKEY_CURRENT_USER\Printers\Settings
Add a DWORD entry with name PreferredConnection and value of 0)
Reboot.

Printing from Android

Android doesn’t support direct printing, so we’re left with an another app.

From what I’ve found so far, there’s only 1 that is Ad-free, easy to setup, and not too big: Let’s Print Droid (BlackSpruce). You can either print directly from the app, or print with Let’s Print Droid through the common share options in other apps.

201608_and000

In Google play, search for and install “Let’s print Droid”. Use the same as used in Windows: http://HOST:631/printers/Printer_Name

This is what I use:
Printer Name: Canon_MG5100
Protocol: IPP/CUPS print server
IP Address: 192.168.0.240
Port Number: 631
Queue/Share/Dir Name: /printers/Canon_MG5100
Page Description Language: PS – Postscript

Printing through Samba?

Now we get into the nuts and bolts of setting up our print and file server. Here’s how to share out printers so everyone can use them. First, enter sudo nano /etc/samba/smb.conf. Once the file is open, look for these two sections:

[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
guest ok = no
read only = yes
create mask = 0700

The first section is the basic entry for sharing out printers with Samba. Let’s break this down:

[printers]: Name of the directive.
comment = All Printers: The human readable comment.
browseable = no: This controls whether this share is seen in the list of available shares in a net view and in the browse list. Set this to “yes” so users can see the listed printers.
path = /var/spool/samba: Path to the printer spool.
printable = yes: Set to “yes” to allow users to print.
guest ok = no: Set to “yes” to allow guest users (anyone) to print to the printer.
read only = yes: If set to “no” users will be able to create and modify files in the service’s directory.
create mask = 0700: How the “create file” permissions are handled.
For a print server that is going to allow all users (guests) to print to the configured CUPS printers, the only thing you would need to change in the above section is the “browseable” and “guest ok” entries.

The second print section shown below should include any necessary Windows drivers for downloading to clients.
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = no

The above section should be fine as is, but there might be one issue depending upon your setup: You have to copy all driver files into the directory configured above (in the sample it’s /var/lib/samba/printers/). If you don’t set “guest ok” to “yes,” users may have to have a Samba username and password in order gain access to the necessary files. If you cannot open that directory to everyone (by setting “guest ok” to “yes”), you might have to add users to Samba using the smbpasswd tool. If you have a lot of users, it might be best to open the floodgates. We can be safe and house those files in a location such as /opt/printdrivers/ and then set “guest ok” to “yes.”

Let’s not forget this under [global]:
disable netbios = yes
smb ports = 445

After we make the changes in the smb.conf file, we need to restart Samba with the command
sudo service samba restart