GTKC Knowledgebase
A little bit of wisdom
Share a USB device over the network
Posted by  Admin on


I have a Canon TS3100 printer / scanner, which is USB only.

I wanted to be able to access this printer across the network.

Of course it's possible to share the printer using Samba (Linux) or Windows file sharing, however the scan and status utilities no longer function.

The solution was to share the USB port on the network, and this is how I did it.

The printer is connected to my Linux (Debian) NAS.

I started by installing the usbip package apt install usbip which also brings in the usbipd daemon.

As no startup (systemd unit) files were created, I had to create these myself.

Start by creating the usbipd daemon unit file which resides in /etc/systemd/system/usbipd.service

[Unit]
Description=usbip host daemon
After=network.target

[Service]
Type=forking
ExecStartPre=/sbin/modprobe usbip-host
ExecStart=/usr/sbin/usbipd -D --ipv4

[Install]
WantedBy=multi-user.target


As my system is ipv4 only I added the --ipv4 switch - this is not necessary if you are running ipv6

I then created a config file in /etc/usbip-devices/canon.conf which contains the device ID.

You can find the device ID by running usbip list -l which in my case displayed the following:
 - busid 2-3 (04a9:1827)
   Canon, Inc. : unknown product (04a9:1827)


The part of interest is the busid number which as can be seen here is 2-3.

Contents of /etc/usbip-devices/canon.conf
OPTIONS="--busid=2-3"


I then went on to create the usbip startup unit file which I name /etc/systemd/system/usbip-bind.service

[Unit]
Description=USB/IP Device Canon
Requires=usbipd.service
After=usbipd.service

[Service]
EnvironmentFile=/etc/usbip-devices/canon.conf
RemainAfterExit=yes
ExecStart=/usr/sbin/usbip bind $OPTIONS
ExecStop=/usr/sbin/usbip unbind $OPTIONS

[Install]
WantedBy=multi-user.target


These reads the options from the canon.conf file and passes them to usbip.

Once these unit files have been created, you need to run systemctl daemon-reload

You will want the usbipd daemon to start at boot, so run systemctl enable usbipd - you can do the same for usbip if you want that to start at each reboot**.

**NOTE: the USB device you are sharing must be connected otherwise the service will fail to start.

Windows


As I'm printing from Windows I needed to add the necessary usbip drivers and utilities, which can be download from the Github repository here

Once you have download the .zip file, extract it to a temporary folder and run usbip --install which will install the required Windows drivers.

You can now check to see if your device hs been shared successfully by running usbip.exe list -r 172.16.1.9 where you should see output similar to the following:

Exportable USB devices
======================
 - 172.16.1.9
        2-3: Canon, Inc. : unknown product (04a9:1827)
           : /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3
           : (Defined at Interface level) (00/00/00)


If this is successful you can now connect to the shared port by executing usbip.exe attach -r 172.16.1.9 -b 2-3 (note that your USB ID should be the one you determined earlier).

To disconnect the port, simply execute usbip detach --port=0 (your port will possibly be different, and will have been displayed on screen when you attached to the server port).

NOTE: all the above commands need to be run as administrator.

Tags: Linux , USB , Networking

Return to home page: Home