Use Jolla Phone to share Wifi via USB

Recently I got a new Surface Pro 4, and starts to use it as my main laptop. I’m glad that it can work with Linux quite well. But it does have some issue that I can’t live with: wifi will stop working after hours randomly.

Though someone points a workaround to me on reddit, but it does not work for me. Fortunately, I was able to just use my usb ethernet at that time. But recently, I moved my seat at home to a place where I couldn’t reach the ethernet cable, so I has been forced to use wifi since then.

Luckily, I found a thread that indicated that I can make my Jolla phone to share the internet via USB. To make it short, one just need to execute

pkcon install usb-moded-connection-sharing-android-config

with developer account and restart the phone.

But later I found that it only works with Cellular network but not with wifi. I digged into the related usb-moded code to confirm that. The implementation explicitly disables wifi and enables cellular network for sharing.

But this is not the end of the story. I found I can still manually enable wifi after select Internet sharing as usb mode. But the network itself doesn’t work, because the implementation only adds the masquerade iptables rule for the cellular network. So I just tried to add my iptables rule manually via:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

And it works!

Then I created an expect(1) script to ssh to phone and execute the iptables command automatically, so now I can happily use Jolla to connect the wifi network for me, just like using a wifi dongle. I still need to configure the dns server manually via networkmanager for my local connection because the dns server pushed by dhcp server is for cellular network, but that’s good enough since I can even use google’s public dns server blindly if I don’t are too much about the dns speed.

This iptables rule also seems to be persistent if you don’t restart the phone, so I’m also considering to add it when the phone boots. For now I’m happy with my current solution.

This entry was posted in Linux and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.