trents_blog/docs/posts/raspberrypi-lte-failover-router-with-dns-caching.md

5.1 KiB

title date draft tags summaryimage summaryimagew summaryimageh authors post
RaspberryPi LTE-Failover Router With DNS Caching 2021-10-06 false
RaspberryPi
Arch
linux
router
tethering
android
winblows
PXL_20211006_142214161_672x504.png 672 504
trent
23

date: 2021-10-06

Introduction

Apparently Windows has a problem resolving hosts when you tether from Mobile HotSpot.

The solution is to build a DNS-Caching router that tethers off the smartphone. This takes advantage of Android's ability so transparently fail-over to LTE when residential internet service goes down.

This solution also takes advantage of the RaspberryPi's incredibly low price, the fact that LineageOS will run on cheap old phones that are no longer supported by the mfgr, and the fact that GoogleFi will ship you a data-sim for free.

For instance, I just bought a brand-new, open-box Pixel phone for $85, and presumable the MotoX4 can also be had for next to nothing.

Materials

RaspberryPi Router tethered off MotoX4 (running LineageOS)

Setup

Personally I would

Additionally, the router won't be accessible for administrative tasks when it is behind the Android Tether ; for this I would use a wireguard vpn{target="_blank"}.

Configure The Router.

The entire configuration of the router consists of two systemd-networkd interface definitions, as well as /etc/resolv.conf, and /etc/dnsmasq.conf.

resolvconf

systemd-resolved is no use to us because it only listens on localhost.

# disable systemd-resolved
systemctl stop systemd-resolved
systemctl disable systemd-resolved
unlink /etc/resolv.conf

After unlinking the symlinked version of /etc/resolv.conf, write your nameservers and options in a real /etc/resolv.conf.

# the default timeout of 5 seconds is too slow
options timeout:1

# nameserver when connected to lan
nameserver 192.168.1.1
# nameserver when connected to mobile network
nameserver 8.8.8.8

Interface Definitions For systemd-networkd

I believe the usb interfaces are numbered 1-4, so either be careful which one you use, or maybe a wildcard name will work, i.e. Name=usb*

# uplink
# /etc/systemd/network/usb0.network
[Match]
Name=usb0

[Network]
DHCP=yes
DNSSEC=no
IPForward=yes
# downlink, ethernet cable
# /etc/systemd/network/eth0.network
[Match]
Name=eth0

[Network]
Address=10.12.34.1/24
DHCPServer=yes
IPForward=yes
IPMasquerade=both

Configuration For dnsmasq

Install dnsmasq{target="_blank"}, and enable it systemctl enable dnsmasq.

# /etc/dnsmasq.conf
resolv-file=/etc/resolv.conf
interface=eth0
no-dhcp-interface=eth0

Reboot

Plug in the Android Phone, reboot the RaspberryPi, and when it comes back up toggle on the USB tether on the Android Phone.

Plug ethernet cable into Windows Computer, open CMD prompt and type ping google.com to test connectivity and name resolution. Or on a Linux computer type ping -c 3 google.com.

Alternate DHCP Service

You can use dnsmasq for DHCP Service instead of systemd-networkd.

# downlink, ethernet cable
# /etc/systemd/network/eth0.network
[Match]
Name=eth0

[Network]
Address=10.12.34.1/24
# DHCPServer=yes
IPForward=yes
IPMasquerade=both
# /etc/dnsmasq.conf
resolv-file=/etc/resolv.conf
interface=eth0
# no-dhcp-interface=eth0
dhcp-range=10.12.34.50,10.12.34.150

Reference For systemd-networkd

  • examples in /usr/lib/systemd/network/
  • Man Page{target="_blank"}

Use With Multiple Computers

Just add an unmanaged switch{target="_blank"}.

Wifi Instead of Ethernet

Use downlink definition for wlan0 instead of eth0, and install hostapd

# /etc/hostapd/hostapd.conf
interface=wlan0
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=NETWORK
wpa_passphrase=PASSWORD