Introduction: FreeNAS As a Print Server

FreeNAS is an excellent network storage solution simple enough for anyone to install. The system and space requirements are ridiculously small for this stripped-down version of FreeBSD. It's got all manner of features accessible through it's clean web GUI, more than most will ever need. It even lets you stream media to game consoles!

Despite it's impressive built in abilities, there was one thing that I wanted it to do besides act as a great NAS, and that was to be a print server so I could share my HP Deskjet 6540 USB printer among my Windows and Mac OSX boxes. Easier said than done. After hours of playing around with CUPS and a few broken installs later, I saw the light.

On the FreeNAS forums, user sgrizzi created a thread on how to make it work with LPR, using the LPRng package, for a LiveCD based setup. It was EXTREMELY helpful, and he/she should get most of the credit, but the thread really needs to be condensed and clarified to be a useful guide. That is exactly what this Instructable is for, as well as modifying it for a standard full install of FreeNAS.

This guide assumes you already have a current standard install of FreeNAS set up and working.

Step 1: Preparation

First, let's get together a few things and take a look at the setup.

The Network
Your setup may be different, but mine is as follows.
- Linksys WRT54GL router running Tomato firmware v1.23
- FreeNAS box - v0.69, old Sony Vaio, 2 hard drives, static IP: 192.168.1.50
- PC - Windows XP SP3
- Macbook Pro - OSX 10.5.6
- HP Deskjet 6540 - USB connected printer, attached to FreeNAS

You will need to assign your FreeNAS box a static internal IP from within your router. There's plenty of guides online for that, all straight-forward, so do a quick Googling.

Stuff You'll Need
- Windows install disk if you're using Windows (necessary files may be availible elsewhere, but this is the easiest)
- Printer Drivers for your particular make/model
- The file "ulpt.ko" taken from a full FreeBSD install. File attached to this instructable.
- SSH client - For Windows, go with PuTTy. For Linux, Unix, Mac, etc you can just use the terminal/command line

Attachments

Step 2: Connect Via SSH

Connect to your FreeNAS box via SSH. Normally it's bad practice to log in as root, but if you're really careful, things should go smoothly.

PuTTy is pretty self explanatory here for connecting. For the command line people, type:

ssh -l username static_ip_of_freenas

The static ip will be something like 192.168.x.xxx.
It will ask for a password, but when you type, nothing shows up. Don't worry, this is normal (hides password for security purposes); just type it and hit enter.

You should now have yourself a little greeting and a new command prompt (loggin in as root is freenas:~# and as a user is >)

Step 3: Put Ulpt.ko in the Right Spot

Use your preferred method (ftp, smb, etc.) to put the ulpt.ko file somewhere onto the FreeNAS box, and remember the full path (I'll call it UPath), which will probably be something like /mnt/drivename/ulpt.ko

Go back to the terminal with the SSH connection and command prompt, we're going to move the file to the proper place. Type:

mv Upath /boot/kernel/ulpt.ko

That ought to do it.

Step 4: Install LPRng

We will be using a package called LPRng. To install it, type:

pkg_add -r LPRng

Let that chug away for a bit while it downloads and installs the necessary bits.

Step 5: Configure Things to Load on Boot

Load ulpt.ko Module
First we want to make sure that ulpt.ko loads on boot so as soon as we connect a printer it'll recognize it properly. Type:

nano /boot/defaults/loader.conf

Scroll down with either the arrow keys or ctrl+V until you reach a section titled "USB Modules"
Change the line
"ulpt_load="NO" # Printer"
to
"ulpt_load="YES" # Printer"

Hit ctrl+X. Then type "y", and hit enter when it asks you to save.

Start LPRng

Navigate to the FreeNAS web interface in a browser. Then go to System-->Advanced-->rc.conf
Use the "+" button to add two new entries:

Name: lpd_enable
Value: NO

Name: lprng_enable
Value: YES

Step 6: LPRng Configuration: 1 of 3 - Printcap

There are three main files that contribute to LPRng working properly.
- /etc/printcap
- /usr/local/etc/lpd.perms
- /usr/local/etc/lpd.conf

Printcap (location: /etc/printcap) can be very complex or very simple. We'll go with very simple, but you can refer to the LPRng site and google for some different setups depending on your needs.

It'll be much easier to illustrate this by example:

# @(#)printcap HP Deskjet 6540
lp|deskjet:\
:sd=/var/spool/lpd/bare:\
:sh:\
:lp=/dev/ulpt0:
#

First line doesn't matter much. Just put your printer make/model in there for reference
- "lp|deskjet" - this is what you're printer will be known as. "lp" is the primary name, "deskjet" is an alias.
- "sd=" This is the path to the print spooler. We're going to make this directory in a second.
- "sh" This stands for "supress header". If you've ever printed in a computer lab, you'll have seen these. It's a page that prints before a job that identifies who the job is for. For most people at home, it's unnecessary. In a work environment with lots of people and printing, it's something you should look into.
- "lp=" this is the location of the printer. If ulpt.ko loads properly, then when you connect a printer, it should register as /dev/ulpt0.

Remember the spooler path from sd? Let's make it. Type:

"mkdir -p -m 700 /var/spool/lpd/bare"
and
"chown 1:1 /var/spool/lpd/bare"

This creates the proper directory with the necessary ownership and permissions.

Step 7: LPRng Configuration: 2 of 3 - Lpd.perms

lpd.perms (location: /usr/local/etc/lpd.perms) is a bit long. The default configuration should be fine. Scroll through and double check that these lines are uncommented (don't begin with a "#") by typing:

nano /usr/local/etc/lpd.perms

The lines that we want uncommented are:

ACCEPT SERVICE=C SERVER REMOTEUSER=root,papowell
ACCEPT SERVICE=C LPC=lpd,status,printcap
REJECT SERVICE=C
ACCEPT SERVICE=M SAMEHOST SAMEUSER
ACCEPT SERVICE=M SERVER REMOTEUSER=root
REJECT SERVICE=M
DEFAULT ACCEPT

Make any changes and then hit ctrl+X

Step 8: LPRng Configuration: 3 of 3 - Lpd.conf

lpd.conf (location: /usr/local/etc/lpd.perms) should also be fine as the default. Things to double check for:

# Purpose: always print banner, ignore lpr -h option
# default ab@ (FLAG off)
# Purpose: query accounting server when connected
# default achk@ (FLAG off)
# Purpose: accounting at end (see also af, la, ar, as)
# default ae=jobend $H $n $P $k $b $t (STRING)
# Purpose: name of accounting file (see also la, ar)
# default af=acct (STRING)
# Purpose: use long job number (0 - 999999) when a job is submitted
# default longnumber@ (FLAG off)
Longnumber

Step 9: Start Things and Set Permissions When Printer Connects

We're going to want to start up the proper LPRng processes when a printer is connected. Type:

"nano /usr/local/etc/devd/devd.conf"

Add to the file:

# start action when USB printer ulpt0 is plugged in
# wait 3 second and then start the spooler daemon
#
attach 100 {
device-name "ulpt0";
action "sleep 3; lpd;
checkpc -f;
chown 0:0 /dev/ulpt0;
chmod 666 /dev/ulpt0;
echo 'o5L25fgfab' > /dev/speaker;";
};
*/

This watches for the printer to be plugged in, waits a few seconds, and starts the LPD process. Once that's going it fixes any missing files or permissions with checkpc -f. It then sets proper ownership and permissions on the device and plays a little sound.

Step 10: Connecting a Windows PC

1) Go to Network Connections. Click the Advanced tab at the top, then "Optional Networking Components".
Enable both Management and Monitoring Tools and Other Network File and Print services. It will ask you to insert the Windows cd, which you should have around. This will allow us to connect via LPR

2) Go to the Control Panel and then to Printers. Run the Add a New Printer wizard.

3) Local Printer (do not automatically detect). Next.

4) Create New Port -> LPR Port. Next

5) Enter the IP address of the FreeNAS box. This is why we want it to be static. Enter the name of the print queue (if you copied my printcap, it's "lp" without quotes)

6) Install drivers and click through the rest of the wizard. Do not print test page.

7) Right click on the printer and open up properties.

8) Port Tab. Uncheck "bidirectional support"

9) Advanced Tab.
start printing after the last page is spooled. Check
Print directly& Uncheck
Hold mismatched& Uncheck
Print spooled& Check
Keep&.Uncheck
Enable advanced& Check

10) Now go back to the main tab and try printing a test page.

Step 11: Connecting With Mac OSX

1) Open up System Preferences -> Print and Fax

2) Click the "+" to add a printer

3) Go to the "IP" tab
Protocol: LPD
Address: The IP of FreeNAS
Queue: Name of print queue (if you copied my printcap, it's "lp" without quotes)
Name and Location are up to you
Print Using: Pick correct drivers*

*Some printers, like my HP Deskjet 6540 wouldn't let me use the usb drivers with the LPD. I had to instead pick one as close as possible (turned out to be 5550) and go with that. If the two models are similar, it should work without a problem.