Sharing a scanner over the network using SANE is fairly straightforward. Here's how I shared a scanner on a server (running Debian jessie) with a client (running Ubuntu trusty).
Install SANE
The packages you need on both the client and the server are:
You should check whether or your scanner is supported by the latest stable release or by the latest development version.
In my case, I needed to get a Canon LiDE 220 working so I had to grab the libsane 1.0.25+git20150528-1 package from Debian experimental.
Test the scanner locally
Once you have SANE installed, you can test it out locally to confirm that it detects your scanner:
scanimage -L
Note that you may need to be root for this to work. We'll fix that in the next section.
This should give you output similar to this:
device `genesys:libusb:001:006' is a Canon LiDE 220 flatbed scanner
If that doesn't work, make sure that the scanner is actually detected by the USB stack:
$ lsusb | grep Canon
Bus 001 Device 006: ID 04a9:190f Canon, Inc.
and that its USB ID shows up in the SANE backend it needs:
$ grep 190f /etc/sane.d/genesys.conf
usb 0x04a9 0x190f
To do a test scan, simply run:
scanimage > test.pnm
and then take a look at the (greyscale) image it produced (test.pnm
).
Letting normal users access the scanner
In order for users to be able to see the scanner, they will need to be in
the scanner
group:
adduser francois scanner
adduser saned scanner
with the second one being for remote users.
Next, you'll need to put this in /etc/udev/rules.d/55-libsane.rules
:
SUBSYSTEM=="usb", ATTRS{idVendor}=="04a9", MODE="0660", GROUP="scanner", ENV{libsane_matched}="yes"
and then restart udev:
systemctl restart udev.service
That 04a9
ID is the first part of what you saw in lsusb
, but you can
also see it in the output of sane-find-scanner
.
Finally, test the scanner as your normal user:
scanimage > test.pnm
to confirm that everything is working.
Configure the server
With the scanner working locally, it's time to expose it to network clients
by adding the client IP addresses to /etc/sane.d/saned.conf
:
## Access list
192.168.1.3
and then opening the appropriate ports on your firewall
(typically /etc/network/iptables
in Debian):
-A INPUT -s 192.168.1.3 -p tcp --dport 6566 -j ACCEPT
-A INPUT -s 192.168.1.3 -p udp -j ACCEPT
Then you need to ensure that the SANE server is running by setting the
following in /etc/default/saned
:
RUN=yes
if you're using the sysv init system, or by running this command:
systemctl enable saned.socket
if using systemd.
I actually had to reboot to make saned visible to systemd, so if you still run into these errors:
$ service saned start
Failed to start saned.service: Unit saned.service is masked.
you're probably just one reboot away from getting it to work.
One more time you may want to do on the server is to comment out the pixma
line in /etc/sane.d/dll.conf
if you don't need that backend. When it's
enabled (in use or not), it ends up sending broadcast packets on UDP ports
8612 and 8610 on the local network. If you want to avoid seeing this on
your endpoint firewalls, simply disable that backend.
Configure the client
On the client, all you need to do is add the following to
/etc/sane.d/net.conf
:
connect_timeout = 60
myserver
where myserver
is the hostname or IP address of the server running saned.
If you have a firewall runnning on the client, make sure you allow SANE traffic from the server:
-A INPUT -s 192.168.1.2 -p tcp --sport 6566 -j ACCEPT
Test the scanner remotely
With everything in place, you should be able to see the scanner from the client computer:
$ scanimage -L
device `net:myserver:genesys:libusb:001:006' is a Canon LiDE 220 flatbed scanner
and successfully perform a test scan using this command:
scanimage > test.pnm
Troubleshooting connection problems
If you see the following error in your logs (systemctl status saned.socket
):
saned.socket: Too many incoming connections (1), dropping connection.
then you can work around this bug in the systemd unit by overriding the systemd unit that comes with the package:
cp /lib/systemd/system/saned.socket /etc/systemd/system/saned.socket
then replace:
[Socket]
MaxConnections=1
with:
[Socket]
MaxConnections=64
before finally restarting the service:
systemctl daemon-reload
systemctl restart saned.socket
Printers are devices you have to physically move to as well and they are networked all the time. So it makes sense to network a scanner for similar reasons and more:
a scanner has to be networked to scan to a network destination like a shared drive or scan directly to email
It makes no sense to have a scanner for each person in an office, so you can share the scanner just like sharing a printer. Otherwise the computer with the scanner connected has to be physically logged onto and used to scan instead of controlling it right from your own computer. This can be handy if you are scanning and need to try multiple times to get the settings right too.
Of course this mainly applies to scanners that do not have built in networking ability (usb only connections). If they do have built in servers it makes less sense.
sane is supported on windows (Xsane for win32, SwingSane), but only as a network client. You can't plug a scanner into a windows machine with USB and use sane, but you can plug a scanner into a linux machine, run saned, and then connect sane on windows to that.
Why would you do this? HP Multifunction printers are notorious for not supporting the latest version of windows. HP will make a "universal print driver" and ignore the scanner. So anyone with an older device (something made for XP or Win9x) can't scan from windows normally. saned keeps these devices alive.
i setup a network scanner here because it is also a printer and already connected, by USB, to a print server so that many people can print on it without having to worry about cabling.
yes, they need to move their feet to get actual paper in and out of there. crazy physics. but it beats fiddling with wires.
also i figured i would mention there is a similar guide in the Debian wiki - which seems to have slightly better SEO, so it comes up first. Therefore, I have reworked it to include the excellent suggestions here that were missing there. See if you can improve it further!
i also wonder if we could get this simplified somehow. i don't mind configuring the server so much, but it's kind of painful to have to edit config files by hand on each client that needs to be configured...
can't Avahi take care of this for us, just like it does for CUPS and printing? i looked around for this feature but so far all I've found are bug reports saying that it doesn't work (ubuntu LP#508866, debian #743420). and indeed, with
SANE_DEBUG_NET=128 scanimage -L
says:So I'm not sure what's going on, but clearly this is not working...
On Debian jessie and stretch there is no need for a user to be in the scanner group.
https://wiki.debian.org/Scanner
Cheers,
Brian
The instructions in this blog are spot on: everything worked right away (well, except the FW rule, but this is a very minor issue) and I ended up doing some googling for the Windows SANE client and found SANEWinDS on source forge. Works standalone and from Open Office and I am happy camper.
Thanks a lot for putting together this concise instruction, it saves my users from moving files around from the scanner sharing machine!
After encoutering numerous problems in setting up SANED network access with systemd on a Linux Mint 18.3 , here are some important points
1) make sure you do not have saned configured to run under inetd or xinetd as might be the case from an upgraded installation
2) systemd needs a file for socket and an instance service file. To avoid loss of customizations with package upgrades, put these in /etc/systemd/system not overwrite those in /lib/systemd/system
The second item it needs is an instance service file NOT a service file. This means that the file name contains an "@" as in saned@.service and the contents
If you want to do debugging you can add additional Environment lines
For completeness, to mirror the setup in /lib/systemd/system and to emphasize the point when looking in /etc/systemd/system that the file is not missing and that saned@.service is not misnamed, symbolically link /dev/null to /etc/lib/systemd/system/saned.service
This is unecessary because of the link present in /lib/systemd/system, but it makes it clear when looking at the /etc/systemd/system directory the configuration being used.
Do a systemctl enable of saned.socket and it will create a symbolic link under the socket.target.wants directory
/etc/services should have the entry
Ensure that /proc/sys/net/ipv6/bindv6only is set to 0 (and not set to 1 due to some hack from an old bindipv6only.conf file /etc/sysctl.conf.d) if you are wanting network connections on IPv4 to work.
It may be necessary to ensure that the "net" featured is turned on in /etc/sane.d/dll.d configuration file for your scanner if it is some non-standard configuration.
In your /etc/sane.d/saned.conf ensure your have a "localhost" entry -- 127.0.0.1 should also work but when saned starts up it says checking for localhost, so this is to be consistent. Then add the host names or network IP address ranges permitted to access the service.
Adjust your firewall rules if necessary.
You do not need to add the host IP address to the /etc/sane.d/net.conf file, this will result in you being offered both a local and a network connection to the scanner from the host, so keep it simple for the server host, but do add the server host IP address or name to the net.conf file on the client hosts which need to access the service.
If you then do a systemctl start saned.socket followed by a systemctl status saned.socket you should see
Now where the "magic" comes in, is that when a connection is made on the socket, systemd fires up an instance of the saned service using the socket name as the instance name (which is why the standard input is set to "null" and NOT "socket" in the saned@.service file).
So if when a remote connection is made you do
where the instance number increases by one for each connection.
If you want to advertise the service via Avahi, you could add a service file under /etc/avahi/servvices
replacing example.COM and server_name as appropriate. The value for "type" was taken from
This document is about how to use SANE to share a USB scanner over the network, and it seems to use some SANE-specific protocol. All the comments in the relative configuration files are written as if the remote scanner was an instance of SANE on a Linux machine.
In my case, the scanner has built-in network support, and I haven't found any evidence that SANE supports this use case. That's unfortunate, since CUPS supports the printer portion of that device without much difficulty. I can't get the scanner close enough to my PC for a USB connection, so it looks like the only way I'm scanning from this thing from Linux is if I put a Raspberry Pi next to it just so it can serve SANE to me.
@Some Guy: there exist backends to make directly-network-attached scanners available to the sane ecosystem. Look for "sane-escl" (part of core Sane project, airprint/airscan protocol) and/or "sane-airscan " (3rd party open source, airprint/airscan + Microsoft WSD "WEB Service for devices" ).
Debian Wiki goes into more detail: SaneOverNetwork > escl protocol