USB Tethering: assigning static IP addresses

Hello,
I noticed that with the latest /eOS release, 1.5, the IP mask assigned to an external device connected via USB tethering is not constant, so that the IP of that device changes everytime the USB tethering is reconnected.

This wasn’t happening with previous versions of the system and it’s causing me some troubles, as I’d like the IP to be static and to survive across reconnection.

Does someone have some hints?

Thanks

usb tethering - the smartphone is offering its network via usb, not the other way round?

Is the it deterministic, like the ip changes on every creation of the link? is the link MAC the same across reconnects, even as the IP changes?

On an Ubuntu-based laptop, connected via USB to the Fairphone with /s/OS:

image

Reconnect (switch off / switch on) USB tethering on the smartphone:

image

Do you need some additional information?

did you change major Android versions at the same time? I use the usb-tether feature seldomly so can’t say if Android R was different. But yes, I see what you describe (in 1.5 S)… but can’t find an option to make the usb tethering static. Read the docs on the wifi mac-randomization, but no mention of usb


|
tcecyk

November 22

|

  • | - |

did you change major Android versions at the same time?

Yes, before 1.5 it wasn’t happening.

Hi,
for me, tethering not runs on linux , but ok with windows : i work on linux , so disturbing … This, until the 1.0 version , approximately: it was ok before .

It would be great to have some maintainer shedding some light on this.

The best would be an advanced config option to choose the IP mask of the USB tethered network.

Instead of writing here, you may have better luck by browsing or opening an issue : Report an issue

I don’t think this is up to /e/ but is just a default with newer Androids. The tethering code changed between Android 10->11 and again 11->12. Before 10 it was static, then it it was stable mac+ip via dhcp in 10 (e, then stable mac, dynamic dhcp ip in 11, in 12 you get random mac and dynamic ip.

There are some config flags that you could try to change the behaviour, are you on S / A12 ? see “tether_enable_legacy_dhcp_server” at packages/modules/Connectivity/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java

not sure how to set it though - either via “adb shell settings put global tether_enable_legacy_dhcp_server 1” or some "adb shell content query --uri content://settings/ … " (then use update instead of query)

Thanks!

./adb shell settings put global tether_enable_legacy_dhcp_server 1

./adb shell settings get global tether_enable_legacy_dhcp_server

1

But still random IPs.

I’m on /e/OS 1.6, Android 11.

yes, not reverting to dnsmasqs old dhcp ranges in Android 12 at least - but Android 10 release notes also say the same, it’s supposedly a global setting - Android 10 release notes  |  Android Open Source Project

What is bothering you with the ip address being in the /16 range? maybe there’s another solution what you described as “causing you trouble”

As part of my tasks in my job position, I need to demo an Android application that connects to a service installed locally in the laptop. So, I need to have a shared local network in which the Android application sees that service and I achieved that with USB tethering + bridging in the laptop-

Access must happen via a FQDN, not just IP, so I need to define the corresponding records in the DNS zone. This is why I need the IP to be the same after a switch off / switch on of USB tethering.

I hope that this clarify the scenario.

Is the command ./adb shell settings put global tether_enable_legacy_dhcp_server 1 supposed to switch back to the previous behaviour?

fqdn because of selfsigned certificates? ideas…

  1. no fqdn but very easy: adb reverse <laptop> <android> as in … tcp:8000 tcp:8000 and connect through http://localhost:8000 on the Android
  2. a dhcp you control: let the laptop act as AP via wifi - you’ll have full control on dns and ip address of the AP, phone connects to Laptop AP. Downside: if you need an internet uplink at the same time, but there are solutions too (ap+sta mode combined, ethernet uplink + masquerading etc)
  3. there are usb reverse-tethering utils: GitHub - Genymobile/gnirehtet: Gnirehtet provides reverse tethering for Android is very neat and uses a VPN to offer a stable IP ( 10.0.2.2 ). To control fqdn you’d need offer a little dns server of your own. I liked this alot but as “gnirehtet” hasn’t an option to specify an alternative dns port it’s a little hassle to free udp 53 on the hostmachine - but: as you said you already have a dns somewhere which Zones you can edit you’re not deterred - gnirehtet has this as “-d” option if it’s not a authorative dns

Another option would be to change your connection method.
For example, if you can disable WiFi MAC address randomization on your phone (some devices don’t …), you could activate a WiFi access point on your laptop, or use a cheap boxed one.
This way you could manage the IP address for your phone, using a DHCP static lease.