The Storm Ate my Broadband

Like many in the country, the storm has left me feeling somewhat isolated - that is to say my broadband is down. Don't get me wrong, I'm just glad the power is (mostly) back, and I'm far better off than some who've had their lives affected.

The simple fact, though, is that I have things I need to do, and not having a broadband connection really gets in the way of that.

Living where I do, there's precisely one place in the house that gets a 3G signal, unfortunately that place isn't particularly conducive to sitting comfortably. Whilst the Wifi hotspot functionality on my phone helps, the range isn't great enough to let me sit somewhere that I might be able to concentrate.

So, somewhat convoluted workaround needed;

To get around the issue, we're aiming for best case scenario (I get to use the PC rather than having to use the laptop). Seems silly not to, given that some effort needs to be put in anyway, so the eventual connection will look like this

PC -> Laptop -> Phone -> Internet

For the pedantic, there is a link missing there, but it should be obvious (Phone -> Charger!).

There's no ethernet connectivity upstairs, and the Wifi interface will be in use to connect to the phone's hotspot (though I suppose I could have used USB tethering) so I've used a Powerline device pair to extend my wired network up to where it needs to be for this (somewhat rushed) project.

 

Configuring the Laptop

First, the laptop needed configuring to route traffic appropriately. So before even connecting the the wifi hotspot, let's take a look at the routes

ben@Enterprise:~$ route -n                                                                                                                                                          
Kernel IP routing table                                                                                                                                                            
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface                                                                                                      
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0                                                                                                       
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 eth0

So, next is to connect to the wifi hotspot, which gives wlan0 an IP within 192.168.43.0/24

Once this is done, though, we still can't ping the internet. The laptop (generally, quite rightly IMHO) is preferring the ethernet connection as the default route. Quick fix

ben@Enterprise:~$ route add default gw 192.168.43.1
ben@Enterprise:~$ route del default gw 192.168.1.254

So let's check our routes now

ben@Enterprise:~$ route -n                                                                                                                                                          
Kernel IP routing table                                                                                                                                                            
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface                                                                                                      
0.0.0.0         192.168.43.1    255.255.255.255 UGH   0      0        0 wlan0                                                                                                      
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0                                                                                                       
192.168.43.0    0.0.0.0         255.255.255.0   U     2      0        0 wlan0                                                                                                      
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0

Can we now ping the outside world?

ben@Enterprise:~$ ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=43 time=1910 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=43 time=912 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=43 time=113 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2007ms
rtt min/avg/max/mdev = 113.195/978.935/1910.919/735.411 ms, pipe 2

Yes we can! Helpfully traffic to 192.168.1.0/24 is still going over eth0, less helpfully the laptop is using the wrong DNS server (there's one on the LAN, but it's currently blind), so we need to update /etc/resolv.conf

# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 192.168.43.1

We can now access the internet properly from the laptop. Pity it needs to sit somewhere that I can't comfortably sit

 

Configuring the PC

If this were a long-term implementation we'd probably configure the laptop to NAT traffic from eth0, but as it's only intended to be in use whilst the main connection is down, it hardly seems worth playing with iptables when there's a quicker and easier solution.

We're going to create a SOCKS proxy on the PC, and send all traffic through an SSH tunnel to the laptop. Simples.

ben@milleniumfalcon:~$ ssh -D 1084 ben@192.168.1.5

Under ordinary circumstances, that would be enough. The problem is the PC can't currently place DNS requests. It seemed silly to go through the hassle of installing DNSMasq or Unbound on the laptop (especially as the packages would need to come down over a 3G link), so I went with the easy solution.

In Firefox, open about:config. Create a new boolean called

network.proxy.socks_remote_dns

Set it to true.

Now when we tell firefox to use our SOCKS proxy, DNS queries will also be sent through the tunnel.

The last step is truly billy-bones basic, in Firefox

Edit -> Preferences -> Advanced -> Network -> Connection Settings.

Set the proxy to Manual and enter the following

Host: 127.0.0.1
Port: 1084
SOCKS v5
No Proxy for: localhost, 127.0.0.1, 192.168.1.0/24

Save the settings, and then visit www.google.com. It should load quite happily now

Configuring FileZilla is no harder

Edit -> Settings -> Generic Proxy

Using the same proxy settings as in Firefox - Helpfully it'll automatically route DNS through the proxy. SSH is even simpler, we just SSH onto the laptop first (why mess around?)

 

Not quite bulletproof

One key advantage of using the laptop as an intermediary (aside from the fact I had no choice) is that when the power trips out briefly, most of my work isn't undone.

I say most, because when the router comes back online the laptop renews it's DHCP lease and overwrites my changes to the routing table (or more specifically, switches the default gateway), so I have to reset that. Beats setting everything up though.

I had thought that if there was a prolonged outage, I could get away with sitting uncomfortably for a bit and using the connection from the laptop. Unfortunately no such luck, when the power drops out the local base-station loses power too so my data connection disappears.

It still beats not getting online at all though!

 

Update

I quickly got fed up with having to manually re-instate routes whenever the power went, so ran the following on the laptop

while [ 1 == 1 ]
do
route -n | grep "0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0"
if [ "$?" == "0" ]
then
route add default gw 192.168.43.1
route del default gw 192.168.1.1
fi
sleep 30
done

The laptop now checks every 30 seconds whether the routes are correct. It takes longer than 30 seconds for the 3G connection to come up anyway so seemed like a good value