Building a scan server on Ubuntu Server 12.04

I have an old but capable little Canon scanner that I’ve used for various administrative tasks for a couple of years now. It connects to my laptop via USB, and draws its power from that link too, which makes it very convenient and easy to use.

Except for the last few months, my daughters have started making increasing use of the scanner for their homework too. Which is fine, but means that the scanner is being carried around the house, and regularly being plugged in and out of different laptops. Which is probably not a good recipe for a long and trouble-free working life.

So today I configured a simple scan server. The scanner is now “permanently” attached to my home server, and anyone who wants to scan documents can do so from their own computer, over the network, using the scanner on the home server. No more hunting for missing USB cables, or even a missing scanner!

This is surprisingly easy to achieve under Linux, as the scanning subsystem (SANE) is implemented as a client/server system, much like the printing system. The only thing that makes it a bit more convoluted is the involvement of a superserver like inetd or one of its equivalents.

On the server:

  1. Plug in the scanner
  2. sudo apt-get install sane-utils
  3. Make sure your /etc/services file contains:

    sane-port 6566/tcp sane saned # SANE

  4. Configure inetd or xinetd to autostart saned. In my case I use xinetd, so I need to ensure that /etc/xinetd.d/saned contains:

    service sane-port
    {
    port = 6566
    socket_type = stream
    server = /usr/sbin/saned
    protocol = tcp
    user = saned
    group = saned
    wait = no
    disable = no
    }

    Now restart xinetd (by sudo /etc/init.d/xinetd restart) so that saned can be autostarted when it’s required.

  5. Next we need to configure saned. This is controlled by the file /etc/defaults/saned, which should be changed to look like:

    # Defaults for the saned initscript, from sane-utils

    # Set to yes to start saned
    RUN=yes

    # Set to the user saned should run as
    RUN_AS_USER=saned

  6. At this point we need to make sure that saned can access the scanner. I did this by setting up a udev rule to arrange for the permissions on the underlying device to be set so saned can access it. For my convenience I also set up a “well known” symbolic name (/dev/scanner) to the scanner device too, as that base device can change depending on what is plugged into the server at any point in time; I’m pretty sure saned doesn’t require this though. I achieved this by making the new file /etc/udev/rules.d/90-scanner.rules contain the single line:

    ATTRS{idVendor}==”04a9″,ATTRS{idProduct}==”2206″,SYMLINK+=”scanner”,MODE=”0660″,OWNER=”root”,GROUP=”saned”

    The idVendor and idProduct are obtained by running the lsusb command, and extracting the USB vendor and product identifiers from the scanner entry.

  7. Next we need to configure saned. In this case, all we need to do is define the systems that can connect to it. This is done by making the file /etc/sane.d/saned.conf read:

    # saned.conf
    # Configuration for the saned daemon

    ## Daemon options
    # Port range for the data connection. Choose a range inside [1024 – 65535].
    # Avoid specifying too large a range, for performance reasons.
    #
    # ONLY use this if your saned server is sitting behind a firewall. If your
    # firewall is a Linux machine, we strongly recommend using the
    # Netfilter nf_conntrack_sane connection tracking module instead.
    #
    # data_portrange = 10000 – 10100

    ## Access list
    # A list of host names, IP addresses or IP subnets (CIDR notation) that
    # are permitted to use local SANE devices. IPv6 addresses must be enclosed
    # in brackets, and should always be specified in their compressed form.
    #
    # The hostname matching is not case-sensitive.

    #scan-client.somedomain.firm
    #192.168.0.1
    #192.168.0.1/29
    #[2001:7a8:185e::42:12]
    #[2001:7a8:185e::42:12]/64
    192.168.255.0/24

    # NOTE: /etc/inetd.conf (or /etc/xinetd.conf) and
    # /etc/services must also be properly configured to start
    # the saned daemon as documented in saned(8), services(4)
    # and inetd.conf(4) (or xinetd.conf(5)).

    In this case you can see I’ve defined it so anything in the 192.168.255.xxx subnet can connect to saned.

On a standard Ubuntu desktop client, only one action needs to be taken to allow it to seamlessly make use of the scan server:

  1. Modify the /etc/sane.d/net.conf file, so it reads:

    # This is the net backend config file.

    ## net backend options
    # Timeout for the initial connection to saned. This will prevent the backend
    # from blocking for several minutes trying to connect to an unresponsive
    # saned host (network outage, host down, …). Value in seconds.
    connect_timeout = 20

    ## saned hosts
    # Each line names a host to attach to.
    # If you list “localhost” then your backends can be accessed either
    # directly or through the net backend. Going through the net backend
    # may be necessary to access devices that need special privileges.
    # localhost
    # My home server:
    192.168.255.20

  2. From this point onwards, you should be able to start “Simple Scan” on the client machine, and see the scanner attached to the server machine, as though it was locally attached. You can alter all the settings as required, and scan over the network as needed.

    Advertisements

9 thoughts on “Building a scan server on Ubuntu Server 12.04

    • Well, either will work, but I guess you can argue that /etc/default/saned is the “better” place to make the change to the config in a Debian-based distro as it can then withstand a package update. Best practice is always good 🙂
      Since I always reinstall rather than upgrade it’s just tnever affected me (yet!)

  1. The file shown in step 5 matches /etc/defaults/saned and is completely different from the contents of /etc/sane.d/saned.conf appearing in step 7. I’m pretty sure you just typed the wrong file name in step 5…

    Those values get sucked into /etc/init.d/saned at init time, so they’re used during normal operation, not just at package config time. The fact that *other* default files contain package configuration settings is just, well, confusing.

    Keeping up with all these changes requires a whole Internet of folks figuring them out; I’m falling behind at an increasing pace!

    Carry on…

    • D’Oh! You are so right … and I still missed the typo, even after you’d pointed it out to me. Hopefully all fixed now.

      I quite like the idea of /etc/default and the way it acts as a local configuration file for “system settings” on client machines where package updates might clobber them. But it all adds to the complexity, and it’s one more place to remember to look when something isn’t behaving the way you expect it to. And I really think it’s overkill on a server machine. But then that’s just my $0.02 🙂

  2. Pingback: SANE: Network Access to a USB Scanner in Xubuntu 12.04 « The Smell of Molten Projects in the Morning

  3. Under Ubuntu 14.04 LTS there appears to be a bug in the sane backends that is causing problems with USB scanners. For the time being, until this bug is fixed, just following this post on an Ubuntu 14.04 machine will probably not work. Sorry!

  4. Pingback: Scanner Server Ubuntu 14.04 | Monotok

    • Hi Mauro, I’ve only one scanner so I’ve never tried it, but I believe it should work. SANE just provides the software (organised as client and server packages) that manage your scanners and makes them available to front-end applications (like Simple Scan) by way of a standard set of APIs. As I describe in my original post, it also allows us to put a network between the client and server portions of SANE, but that’s not really important to it’s basic functionality.
      The right scanning application should be able to select one scanner from a set of scanners that SANE is making available to it, and if you have several such front end applications, I see no reason why SANE wouldn’t be able to connect each of them to a different scanner at the same time. If you have more than one scanner, it should be easy to test. Alternatively you could ask on the SANE mailing list or IRC channel, see http://www.sane-project.org/mailing-lists.html
      Edit: I should have also mentioned, Bug 1312594 seems to prevent some common scanners from being recognised under Ubuntu 14.04LTS, so you may experience some weirdness if you are on 14.04 too.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s