Feed on
Posts
Comments

AirPrint jail for FreeNAS

I just switched from Ubuntu Linux to FreeNAS on my home server. On Ubuntu, CUPS (the printer framework we will configure in this guide) is already patched for AirPrint compatibility. On FreeBSD (thats what FreeNAS is based on) things are a bit different. This is how I got it to work.

bsd_airprintFirst, create a new jail from the FreeNAS UI (Jails, Add jail). Give it a name, e.g. “airprint”. Give it an unique IP address and mark “autostart”, “VIMAGE” and “vanilla”. Then connect to your FreeNAS using SSH or the UI console. Type jls and note the number of your newly created jail. Then type jexec # csh and replace “#” with the number of your jail.

Now its time to install some software.

First, create a password for the jail’s root user. We need it later for CUPS administration.

passwd

Now install ports as we need to compile things later.

portsnap fetch
portsnap extract

Install prerequisites as a binary packages. You can replace nano with your favorite editor.

pkg install avahi nano gutenprint-cups cups-filters py27-cups

Avahi is responsible for the mDNS announcement, gutenprint-cups provides printer drivers for most printers, cups-filters allows us to use Apple’s URF format and py27-cups is a package with python bindings for CUPS.

As we want CUPS to use Avahi and not mDNSresponder, we have to compile it and not use the binary package. Leave most selections as they are but uncheck “Desktop Icons” and replace” mDNSresponder” with “Avahi”.

cd /usr/ports/print/cups/
make install clean

Now edit rc.conf to enable Avahi and CUPS by adding these two lines:

nano -w /etc/rc.conf

avahi_daemon_enable="YES"
cupsd_enable="YES"

Edit CUPS configuration to access it from within your network.

nano -w /usr/local/etc/cups/cupsd.conf

I use the default config with some minor changes. Note the “Listen *:631” and the “Allow @LOCAL” lines....
Listen *: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>
...
Disable dbus support for Avahi.

nano -w /usr/local/etc/avahi/avahi-daemon.conf

enable-dbus=no

Create these two files for URF support.

echo "image/urf urf string(0,UNIRAST<00>)" > /usr/local/share/cups/mime/airprint.types
echo "image/urf application/vnd.cups-postscript 66 pdftops" > /usr/local/share/cups/mime/airprint.convs

Start CUPS and add a printer using the CUPS admin panel (http://JAILIP:631). More information on adding printers in CUPS can be found in the FreeBSD CUPS documentation.

/usr/local/etc/rc.d/cupsd start

Now we need to announce our printer in the network using Avahi. A handy little python script will create the config for us.

cd /root/

wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
python airprint-generate.py
mv AirPrint-*.service /usr/local/etc/avahi/services/
chmod 444 /usr/local/etc/avahi/services/AirPrint-*.service

For some reason Avahi announces a SSH server in our jail. We can disable this by renaming the ssh service files.

cd /usr/local/etc/avahi/services/
mv ssh.service ssh.service_bak
mv sftp-ssh.service sftp-ssh.service_bak

Start Avahi and check if everything works.

/usr/local/etc/rc.d/avahi-daemon start

11 Responses to “AirPrint jail for FreeNAS”

  1. jon says:

    Thank you for the guide! The instructions were easy to follow and basically it works, however I have the problem noted at http://superuser.com/questions/673880/airprint-and-airplay-on-freenas that the AirPrint announcement seems to stop working after a minute or two.

    Now that FreeNAS doesn’t use Avahi it seems that the “kludge” described in the SuperUser post isn’t useful any more. Just wondering if you have ever come across this issue and if so do you happen to remember how you solved it?

  2. David says:

    I have followed this great tutorial up until the point of adding a printer to cups. My printer (Xerox Phaser 3010N) is not listed so I downloaded linux drivers from Xerox website (DEB and RPM packages are provided) and neither seems to work. I cannot print a test page from within cups. My system is FreeNAS 9.2.1.8 and I am fairly new to FreeNAS so any help would be great.

  3. Rifas says:

    Working up to running a python script airprint-generate.py
    It’s no longer working with Python 2.7 or 3.4

    File “airprint-generate.py”, line 22, in
    import cups, os, optparse, re, urlparse
    ImportError: /usr/local/lib/python2.7/site-packages/cups.so: Undefined symbol “cupsConnectDest”

  4. Arnold says:

    I’m stuck where I should start cups. It says:

    /usr/local/etc/rc.d/cupsd: Command not found.

    What should I do?

  5. Andy says:

    Thank You for the guide is very clear and easy to perform, like Arnold i’m stuck to :
    /usr/local/etc/rc.d/cupsd start
    /usr/local/etc/rc.d/cupsd: Command not found.
    it seem cannot find cupsd, what can i do ?

    Thanks

  6. Peter says:

    Try

    pkg install cups

  7. shad0wca7 says:

    Great guide however on FreeNAS 9.10 it seems that the permissions to view the printer attached via USB are not there – so you can’t add a printer within CUPS. To fix this you can add in steps to:

    – Create /etc/rc.local
    – Place the following inside it:
    “# change permissions in jail for printer
    chmod -R 0770 /dev/usb*
    chmod -R 0660 /dev/ugen*
    chmod -R 0660 /dev/unlpt*
    chmod -R 0660 /dev/ulpt*
    chown -R root:cups /dev/ugen*
    chown -R root:cups /dev/usb*
    chown -R root:cups /dev/unlpt*
    chown -R root:cups /dev/ulpt*”

    – sh /etc/rc.local
    – Then refresh the CUPS add printer page and your printer will be there

    This change will survive a jail restart as well

  8. oliver says:

    Thanks for the guide.

    Somethings I have noticed:
    – py27-cups has been renamed to py27-pycups
    – wget is missing in the list of installed packages but later used
    – when installing a new version of cups a ‘make deinstall’ is needed prior

  9. Neil says:

    Thanks for the great guide and useful comments however I still have a problem with my printer. I have managed to install my canon printer and it is showing in the cups admin panel and will print a test page from there. I am however unable to see the printer on any of my other devices. After starting Avahi I see the message dbus_bus_get_private(): Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory.
    Any help would be appreciated
    Thanks

  10. Philip says:

    Had no problems with this install, thanks for the how-to. There were a few minor modifications as others have noted:
    1) In the pkg install step, I used py27-pycups and excluded gutenprint-cups. I also added “cups”. gutenprint-cups wasn’t in the repo and after looking, it didn’t look like it was required for an HP brand printer.
    2) After changing to the cups directory before compiling, I ran “make deinstall”

    All ran quite smoothly. Thanks much!

  11. Ralf says:

    A big thank you for this tutorial, Kai.
    Had no problems as well with the setup. To confirm the post of Philip, the gutenprint-cups package does not work properly with my BW HP Laserprinter M3035MFP as page margins and alignements do not fit at all. After remiving the gutenprint-cups package and the sole use of the the driver which comes with cups package “HP LaserJet Series PCL 4/5” it works perfectly.
    Thanks

Leave a Reply