My old HP Color LaserJet 2820 is still working great, however it only supports being connected via ethernet or USB. As a workaround I’ve been using “Power Line Communication” to bridge directly from my router to the printer over the electrical wires. Recently I’ve been revamping the home network and wanted to get rid of these last power line connections. Ideally I’d want the printer to join the wireless network.
The arrival of the Raspberry Pi 3 with builtin WiFi seems like a good opportunity to implement this. The raspberry Pi is connected with it’s Ethernet port to the printer. The WiFi is connected to the local LAN where I configured the router to give it a fixed IP address.
Approach 1: Cups printer server
I install the cupsys printing system on the Raspberry Pi, and configure it to properly support the printer (using HPLIP). Besides that, I install a DHCP server to serve the printer an IP address on it’s own private network: The cable between Raspberry Pi and printer. I change the configuration of the printer in Cups on the Raspberry Pi to make the printer shared on the LAN. Now all other computers can just use that shared printer to print. This works really good for printing, however it doesn’t work at all for scanning. When scanning the scanning software (SANE) seems to want to connect directly to the printer and this of course isn’t possible when the printer is on a different network and there is no routing.
Approach 2: Routing
I updated the Raspberry Pi to do routing, by enabling IP forwarding. (uncomment the net.ipv4.ip_forward=1 line in /etc/sysctl.conf ) I also configure my router with an extra route to have it know about the network that is now reachable via the Raspberry Pi. Now the printer can be directly communicated with. This allows me to configure the printer directly again on my Linux laptop. Printing still works fine. However scanning still doesn’t work. When I tell the scanner software the IP address of the printer explicitly, it sometimes works, but most of the time it doesn’t work at all. My guess is that the scanner software relies on some communication that doesn’t work outside it’s own network.
Approach 3: Proxy ARP
To learn more about the technicalities of proxy ARP, read here on Wikipedia, and here on wiki.debian.org. In summary it is a trick that makes it seem to the rest of the network that the Raspberry Pi and the printer are the same. In order for this to work I want the printer to have an address in the same network as the local net. First remove the DHCP server installed for the previous approaches, then install a DHCP proxy. This is easily installed (apt-get install dhcp-helper) and configured (DHCPHELPER_OPTS=“-b wlan0” in /etc/default/dhcp-helper). There are multiple ways to enable Proxy ARP. The easiest is to install (apt-get install parprouted) and configure it. My /etc/network/interfaces now looks like this:
auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf post-up /usr/sbin/parprouted eth0 wlan0 post-down /usr/bin/killall /usr/sbin/parprouted post-up /sbin/ip addr add $(/sbin/ip addr show wlan0 | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev eth0 post-down /sbin/ifdown eth0
With proxy ARP in place the printer still works great, and finally the scanner also works in a stable way.
I could try hooking the printer to the Raspberry Pi via USB. As I’ve never used the printer in this way, I’ve not attempted this.