My Blog

Raspberry Pi Static IP Address for Android USB Tethering

Author: Dmitry Klionsky | Created: 2020-02-22

Recently I deployed my first Raspberry Pi into production :). Shortly after doing that I asked myself - what am I going to do if something goes wrong? What can go wrong? Wi-Fi router replaced or its password changed and there’s no a RJ45 patch cable to connect Raspberry Pi to the router. There’s no a laptop or a card reader. Etc.

How to connect to Raspberry Pi if all I have is my Android phone and a USB cable?

The article Android Raspberry Pi display over USB interested me. It proposed to use VNC Viewer on Android over USB tethering and setup a static IP address for the usb0 interface. It’s usually better to avoid static IP addresses, but it’s a great fit in this case. The steps are hopelessly outdated there and don’t work since Raspbian Jessie in 2016. It took me a while until I made it work. The article How to give your Raspberry Pi a Static IP Address helped me a lot. While playing with Android USB tethering I noticed that even though Raspberry Pi’s IP would changed constantly, the phone’s IP 192.168.42.129 (router) always stayed the same even after phone reboots. The IP from the very middle of the range 192.168.42.* looked very suspicious. It turned out, the IP is indeed hardcoded as USB_NEAR_IFACE_ADDR. This makes the below config pretty stable, at least until the phone maker doesn’t change it.

The steps are:

That’s it! Raspberry Pi is accessible from the phone by 192.168.42.42. Now use whatever protocol is appropriate: SSH, VNC, HTTP, etc.

You can find the Ansible role here.