Getting my backup Internet connection through BlueTooth on Linux

August 12, 2023

Suppose, not entirely hypothetically, that your normal DSL Internet connection is down (for example, because the local phone company did something to your line and hasn't fixed it yet), and you need to get Internet by tethering your Linux desktop machine to your smartphone. The easiest way to do this is to be using a modern Linux desktop along with NetworkManager and so on; at that point you can basically click through the various GUIs to connect to your phone's hotspot through wifi, a direct USB connection, or BlueTooth, depending on what you have available. This will handle joining the phone's ad-hoc wifi network, pairing over USB and/or BlueTooth, and all of the other setup you need. However, I don't use a modern Linux desktop.

I suspect that the second easiest way is to at least have NetworkManager around and running, so that you can configure and activate those connections by hand, possibly with command line tools like nmcli. Although I've considered this sort of use of NetworkManager, I haven't yet set it up so I can't say how well it works.

The third easiest way, at least for me, is to use a direct USB connection between my desktop and my phone. Fedora 37 (and previous versions) more or less magically makes this work (for my phone) so that an 'eth0' USB Ethernet device appears. Once the phone's network connection is present, I can start a DHCP client by hand on that interface to get connected and then bring up my WireGuard tunnel through the phone's NAT. Connecting the phone via USB also is probably the fastest and most reliable connection between the two, and it has the side benefit of keeping the phone charged instead of running down its battery.

However, USB has the small drawback of using a cable, which is a potential problem if for some reason you need to walk around while carrying your phone (for example, if you're waiting for a call from your phone company). My home desktop doesn't have wifi, but it does have a USB BlueTooth dongle I got for other reasons and my phone supports tethering over BlueTooth, so today I gave it a shot. It works, but the command line incantations are a bit obscure and I couldn't find much in Internet searches.

I'm not sure how I got my phone and my desktop paired over BlueTooth, but it appears I managed this trick at some point. Possibly I used to GUI tools from Blueman, but it looks like I have a bunch of the tools listed in the Arch Wiki page on BlueTooth, so I'm not sure which one I used. In any case, once the two had been paired in the past, I could enable the connection with 'bluetoothctl devices' to get the MAC and then 'bluetoothctl connect <MAC>' to connect my desktop to my phone. However, this doesn't automatically create any sort of network device. To do that, I needed to run an additional command, 'bt-network -c <MAC> nap'; this command stays in the foreground and creates a 'bnep0' network device. After that, I did my manual DHCP client stuff on 'bnep0' instead of 'eth0' and it all worked the same.

(In theory bt-network supports 'gn', 'panu', or 'nap' connection modes and I sort of thought I wanted 'panu' (see for example this page). In practice trying either 'panu' or 'gn' caused bt-network to dump core, while using 'nap' made everything work even if it's not supposed to have. On Fedora, bt-network comes from the bluez-tools package.)

I haven't tried to measure the speed or latency of BlueTooth as compared with the USB connection. I would expect it to be worse, and in general I'd rather use USB if I have a choice (and on something with wifi, such as my work laptop, I'd try to use wifi as a fallback, even though it's awkward in my current specific situation).

(There's an Arch Wiki guide on this, but its by hand example uses something called 'pand', which is apparently a long obsolete and removed program from older versions of BlueZ.)

PS: I have no idea how much of this would apply to Android phones.

PPS: An interesting side effect of connecting my desktop to my phone over BlueTooth is that my desktop's audio became the phone's default audio output. Probably there are ways to control this so that my desktop doesn't advertise to the phone that it's an audio device and I'm only using the phone for its Internet connection, but right now I can't be bothered to figure them out. And in the mean time it's cute to find out that the phone even sends track information to my desktop (which I saw by leaving 'bluetoothctl' running after I'd (re)connected).

Written on 12 August 2023.
« Some problems with 'first name' and 'last name' fields in data
The tangled problems of asking for people's '(full) legal name' »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Aug 12 22:52:59 2023
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.