At boot, how is "LAN IP" determined?

I have a Pi4, running DietPi v8.14.2. I enabled g_ether and that worked great to give me a new interface usb0 which I use to connect to my Pi4 from a PC over a USB cable. I added the file /etc/network/interfaces.d/usb0.conf and it worked nicely without much effort. So now, my Pi4 has eth0 (DHCP, wlan0 (DHCP, and usb0 (static Then I noticed two things: 1) when trying to change from DropBear to OpenSSH it failed on the ping to, and 2) I couldn’t ping out to the Internet. This was odd since eth0 and wlan0 were getting legit addresses and they were connected to an upstream router where other devices had Internet connectivity. I happened to notice on the DietPi welcome screen (where the DietPi version is printed…e.g. “DietPi v8.14.2 …”) the following message: “- LAN IP : (usb0)”. So with this clue, I removed my usb0 configuration (commented out the line “source interfaces.d/*” from the file /etc/network/interfaces) and now “LAN IP” shown at boot has sometimes shown eth0 and sometimes wlan0 (as expected after removing usb0)…and now Internet connectivity is working…software installation is also working (the ping to works). This “LAN IP” looks like some sort of default…how is it determined and how can I enforce a specific network interface for this default setting? I bet when usb0 is enabled and it appears as the “default” “LAN IP”, the Pi4 is reaching out on usb0 which is connected to my PC which in turn is not sharing its Internet connection (which would explain no route to the Internet). I suppose one solution might be to enable connection sharing on my PC (Windows). But I shouldn’t need to share that connection since the Pi4 has eth0 and wlan0 to get its own Internet.

UPDATE: Enabling connection sharing on my (Windows) PC does indeed allow the Pi4 to get out to the Internet, so that is a workaround (but this workaround has more overhead). Somehow, when my PC is connected via usb0, the Pi4 is using only that interface for network activity, even though eth0 and wlan0 are getting IP addresses assigned from routers that have routes to the Internet. I still think there is probably a way that I can use usb0 without sharing my PC Internet connection since eth0 and wlan0 should provide that route. Any guidance would be greatly appreciated.

Have a look to what default route has been set if you enable your USB network adapter

ip r

What you are doing with multiple interfaces providing internet access and default settings is a bad idea.
If you need all 3 interfaces for a reason, then at least assign interface metrics to give priority to the interfaces which have active internet uplink, otherwise you cannot be sure which one is preferred every time you boot or plug the usb.

@Joulinar: thank you for the tip to investigate ip r – the default route was being assigned to usb0. Once I changed the default route to wlan0, that worked. An additional step I discovered was that I needed to prioritize wlan0 and/or eth0 over usb0…so I updated the metric attribute for those interfaces in etc/network/interfaces. Works as expected now…thanks again!

@trendy: I do need all three interfaces for my application, so it’s not a bad idea – exploring the metric attribute for the interfaces as explained above helped, too, so thanks for that tip!