User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

STICKY: USB Ethernet Gadget A Beginner's Guide

Fri Mar 05, 2021 6:26 pm

2022-04-21: Nwe version:
ethernetgadget.zip
(112.52 KiB) Downloaded 271 times
Added 7.5 Sharing The Zero’s WiFi With The USB Host (github issue #2)
Updated routing instructions for Bullseye (nftables replaced iptables). (github issue #9)
Fixed typo (github issue #4)
Added zero2W.

2021-04-13: https://www.raspberrypi.org/forums/view ... 0#p1851130

Second in an ocasional series.

There's lots of confusion around using the ethernet gadget function on Pi models that support it so another brain dump...
Last edited by thagrol on Thu Apr 21, 2022 1:10 pm, edited 2 times in total.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Ethernet Gadget A Beginner's Guide

Fri Mar 05, 2021 11:47 pm

ieee488 wrote:
Fri Mar 05, 2021 11:45 pm
I have a clean install of Linux Mint 20.1 and local addressing raspberrypi.local does not work.
Please don't hijack this thread. I believe we've discussed that at length elsewhere.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

GlowInTheDark
Posts: 2331
Joined: Sat Nov 09, 2019 12:14 pm

Re: USB Ethernet Gadget A Beginner's Guide

Sat Mar 06, 2021 6:30 pm

Windows 10 works without an issue even with two Zeros.
Wouldn't that be Windows 100?
Poster of inconvenient truths.

Back from a short, unplanned vacation. Did you miss me?

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Ethernet Gadget A Beginner's Guide

Sat Mar 06, 2021 8:16 pm

I'm giving up now.

Mods, please lock this thread. I'm going to delete it.

Given my recent experience I'm no longer going to try to help people. It isn't worth the hassle.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
B.Goode
Posts: 14603
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: USB Ethernet Gadget A Beginner's Guide

Sat Mar 06, 2021 11:20 pm

thagrol wrote:
Sat Mar 06, 2021 8:16 pm
I'm giving up now.

Mods, please lock this thread. I'm going to delete it.

Given my recent experience I'm no longer going to try to help people. It isn't worth the hassle.

I, for one, value having all that information about the various implementations of usb ethernet gadgets and their configuration distilled in one place.

Thank you.

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Ethernet Gadget A Beginner's Guide

Sun Mar 07, 2021 1:12 am

B.Goode wrote:
Sat Mar 06, 2021 11:20 pm
thagrol wrote:
Sat Mar 06, 2021 8:16 pm
I'm giving up now.

Mods, please lock this thread. I'm going to delete it.

Given my recent experience I'm no longer going to try to help people. It isn't worth the hassle.

I, for one, value having all that information about the various implementations of usb ethernet gadgets and their configuration distilled in one place.

Thank you.
You're welcome. I'll leave it up but can't make any promises about when and if it will be updated.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

PhilBr
Posts: 104
Joined: Tue Oct 31, 2017 5:28 pm

Re: USB Ethernet Gadget A Beginner's Guide

Sun Mar 07, 2021 10:22 am

Thanks for your work on this. Looks very useful.
Moderator:. Would you make this a sticky please!
Phil

cleverca22
Posts: 6812
Joined: Sat Aug 18, 2012 2:33 pm

Re: USB Ethernet Gadget A Beginner's Guide

Sun Mar 07, 2021 2:22 pm

thagrol wrote:
Sun Mar 07, 2021 2:19 pm
mahjongg wrote:
Sun Mar 07, 2021 2:12 pm
NO!

Doesn't read like sticky material yet, in fact had to delete many posts, that were deviating from the subject, and were indeed irrelevant.

All posts NOT about Raspberry PI OS, belong in their respective subsection in OTHER (OS) not in threads about raspberry PI OS problems.

Sticky status must be earned before it is given...
Thank for clearing the chaff.

As for sticky status, without it the guide this topic was started with is going to get lost in the forums.

As a moderator, it's your call and I respect that. Just seems a shame to let that happen.
another option is to get it into the official docs: https://github.com/raspberrypi/documentation

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Ethernet Gadget A Beginner's Guide

Sun Mar 07, 2021 2:34 pm

cleverca22 wrote:
Sun Mar 07, 2021 2:22 pm
another option is to get it into the official docs: https://github.com/raspberrypi/documentation
I image there would be some problems with that:
  • The current license the guide has been released under (CC-BY-NC-SA)
  • It would need a rewrite to use the document file format and style guides preferred by RPF/RPT.
But right now having been dragged in circles through this mire by a certain forum user (you know who you are) I'm distinctly lacking the energy and enthusiasm to provide further help to anyone let alone attempt that route.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
bensimmo
Posts: 5746
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: USB Ethernet Gadget A Beginner's Guide

Mon Mar 08, 2021 12:26 pm

It'll get lost.
Perhaps a better idea, rather than lots of stickies. Is to pop up one sticky with Beginners Information and Guides.
Then have these threads linked to (that's be three, your two and the screensaver* one)
Any other useful links could be added (like the official getting started and a link to the troubleshooting guide).

More can be added as time goes by if any useful ones crop up. Restrict posting to it to mods only.

But that's up to the admins and mods.



*though that's more RPiOS than Using the Pi in general.

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Thu Apr 08, 2021 6:46 pm

camila wrote:
Thu Apr 08, 2021 6:12 pm
In the past, a serial debugging adapter was needed to configure the Pi as a USB/Ethernet gadget, but with Raspbian Jessie 5-10-16 or later, all you need to do is edit a couple of files on the SD card.
Nope. It was never needed to configure the gadget, only to debug it.

I guess you haven't actually read the guide. This covered. Please read the latest version of my guide before making further incorrect or incomplete suggestions. Advice of that quality is why I wrote it in the first place.
You’ll need to install a program called Bonjour on your computer before you can connect to the Pi over USB. Bonjour allows your computer to automatically recognize USB and ethernet devices like printers, scanners, and in this case the Raspberry Pi. Bonjour has packaged with iTunes and Adobe CS software, so it might already be installed on your computer. If it’s not though, you can download and install the stand-alone software
Bonjour (aka mdns etc) is a network protocol not a USB one. If the ethernet gadget is working, yeah you can use it (as long as both USB host and zero have it installed) but if you're trying to debug a non working gadget a USB to 3.3v TTL serial dongle is still the best tool. Especially when using a Pi model that works as a gadget but has no on board networking (zero, A, A+, CM, CM3, CM3+) or a USB host that has no network connectivity.

Edit: or you don;t want to further complicate things by having two routes between the devices.
Last edited by thagrol on Thu Apr 08, 2021 6:49 pm, edited 1 time in total.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
B.Goode
Posts: 14603
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Thu Apr 08, 2021 6:49 pm

thagrol wrote:
Thu Apr 08, 2021 6:46 pm
camila wrote:
Thu Apr 08, 2021 6:12 pm
In the past, a serial debugging adapter was needed to configure the Pi as a USB/Ethernet gadget, but with Raspbian Jessie 5-10-16 or later, all you need to do is edit a couple of files on the SD card.
Nope. It was never needed to configure the gadget, only to debug it.

I guess you haven't actually read the guide. This covered. Please read the latest version of my guide before making further incorrect or incomplete suggestions. Advice of that quality is why I wrote it in the first place.
You’ll need to install a program called Bonjour on your computer before you can connect to the Pi over USB. Bonjour allows your computer to automatically recognize USB and ethernet devices like printers, scanners, and in this case the Raspberry Pi. Bonjour has packaged with iTunes and Adobe CS software, so it might already be installed on your computer. If it’s not though, you can download and install the stand-alone software
Bonjour (aka mdns etc) is a network protocol not a USB one. If the ethernet gadget is working, yeah you can use it (as long as both USB host and zero have it installed) but if you're trying to debug a non working gadget a USB to 3.3v TTL serial dongle is still the best tool. Especially when using a Pi model that works as a gadget but has no on board networking (zero, A, A+, CM, CM3, CM3+) or a USB host that has no network connectivity.


How can you possibly argue with someone who has been "working with Raspberry pi boards for 10 years." (sic) ?

Check the new forums user's posting history and recall the advice about feeding You-know-whats.... Lots of drive-by nonsense being sprinkled around!

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Thu Apr 08, 2021 6:56 pm

B.Goode wrote:
Thu Apr 08, 2021 6:49 pm
Check the new forums user's posting history and recall the advice about feeding You-know-whats.... Lots of drive-by nonsense being sprinkled around!
Thanks for the heads up. I missed that they were a new user and dived right in. (and you probably know how I feel about incorrect, incomplete, and/or misleading advice)

Having seen their post history I particularly like this one:
camila wrote:
Wed Apr 07, 2021 11:18 am
I am Camila from the USA. I am an electronics researcher and working with Raspberry pi boards for 10 years.
10 years working with pi boards? Unlikely unless they had links with the foundation before the public release.

Edit: also unlikely given that they only joined the forum yesterday morning.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Tue Apr 13, 2021 6:43 pm

Now available on github with added shell script to configure the gadget using libcomposite/configfs.

No changes to the guide but new zip file attached.

https://github.com/thagrol/Guides
Attachments
ethernetgadget.zip
(108.98 KiB) Downloaded 261 times
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

epoch1970
Posts: 8170
Joined: Thu May 05, 2016 9:33 am
Location: France

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat May 15, 2021 5:57 pm

Just wanted to say thanks for the ethernet gadget guide that I just read.
I thought it was a bit light on the IP side at the end (no bridging, no DHCP...), but it's just me :)

Very nice! Thanks again.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat May 15, 2021 6:39 pm

epoch1970 wrote:
Sat May 15, 2021 5:57 pm
Just wanted to say thanks for the ethernet gadget guide that I just read.
I thought it was a bit light on the IP side at the end (no bridging, no DHCP...), but it's just me :)
Bridging and routinge is covered in section 7.2 of the latest guide.

Running a DHCP server was deliberately ommited as I feel static IPs or link local/mDNS are better options for beginners than configuring yet another service that may not play nice with their USB host.

And if you opt not to use fixed MAC address you'll likely have problems with DHCP anyway.
Very nice! Thanks again.
NP
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
HermannSW
Posts: 5418
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 8:19 am

thagrol wrote:
Sat May 15, 2021 6:39 pm
Bridging and routinge is covered in section 7.2 of the latest guide.
Thanks for the very informative document!

In this thread I finally was able to provide internet access to Pi0W in gadget mode through Pi400 (because where I am currently one device connected to Wifi kicks out other device with same account), with the help of your document and @cleverca22:
viewtopic.php?f=140&p=1906765#p1906386


Some things are slightly different to what you describe, one is missing (default route on Pi0W) in your document, and "sudo netfilter-persistent save" (after installing "netfilter-persistent") has no effect.


These are the steps that finally worked for me:

4.3.3 Unique mac addresses:

Code: Select all

pi@raspberrypi0W:~ $ tail -1 /boot/config.txt 
dtoverlay=dwc2
pi@raspberrypi0W:~ $ echo "..."`tail --bytes 98 /boot/cmdline.txt`
... modules-load=dwc2,g_ether g_ether.dev_addr=12:34:56:78:9a:bc g_ether.host_addr=16:23:45:78:9a:bc
pi@raspberrypi0W:~ $ 

5.2 Picking an IP Address Range (router here is 172...., so choose 192... for static IPs), this method allowed to skip chapter 5.3:

Code: Select all

pi@raspberrypi400:~ $ tail -1 /etc/udev/rules.d/99-com.rules 
SUBSYSTEM=="net",ACTION=="add",KERNEL=="usb0",RUN+="/sbin/ifconfig usb0 192.168.97.1 netmask 255.255.255.0"
pi@raspberrypi400:~ $ 

Code: Select all

pi@raspberrypi0W:~ $ tail -1 /etc/udev/rules.d/99-com.rules
SUBSYSTEM=="net",ACTION=="add",KERNEL=="usb0",RUN+="/sbin/ifconfig usb0 192.168.97.2 netmask 255.255.255.0"
pi@raspberrypi0W:~ $ 

7.2.2 Routed Access:
Did not work:

Code: Select all

echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
Execute once:

Code: Select all

pi@raspberrypi400:~ $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
1
pi@raspberrypi400:~ $
After every reboot (because "sudo netfilter-persistent save" has no effect):

Code: Select all

pi@raspberrypi400:~/Documents $ sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
pi@raspberrypi400:~/Documents $

Missing in ethernetgadget.pdf, on Pi0W:

Code: Select all

pi@raspberrypi0W:~ $ sudo ip route add default via 192.168.97.1 dev usb0
pi@raspberrypi0W:~ $

Finally ping works on Pi0W:

Code: Select all

pi@raspberrypi0W:~ $ ping -c 2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=112 time=24.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=112 time=18.8 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 18.819/21.418/24.018/2.603 ms
pi@raspberrypi0W:~ $ 

Code: Select all

pi@raspberrypi0W:~ $ hostname -I
192.168.97.2 169.254.40.73 
pi@raspberrypi0W:~ $ traceroute 8.8.8.8 | head -3
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  192.168.97.1 (192.168.97.1)  0.559 ms  0.420 ms  0.480 ms
 2  hotspot.kur-br.de (172.27.3.254)  17.624 ms  26.361 ms  36.299 ms
pi@raspberrypi0W:~ $ 
https://hermann-sw.github.io/planar_graph_playground
https://stamm-wilbrandt.de/en#raspcatbt
https://github.com/Hermann-SW/memrun
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 12:47 pm

I'm in the process of doing an update so will investigate.

Can you confirm which OS you have running on both Pi and whether full or lite?

I suspect some of your network problems may be due to you using udev for configuration rather than dhcpcd or /etc/network/interfaces

I've no idea why

Code: Select all

echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
did not work (unless you did not reboot the 400 or restart the service)and I'm surprised that

Code: Select all

sudo tee /proc/sys/net/ipv4/ip_forward
was needed only once as /proc is a virtual file system recreated on each boot. Unless, again, you have yet to reboot the 400.

The quick and dirty fix for those commands that you have found that need to be run at boot would be to add them to /etc/rc.local (above the exit 0 line).
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

cleverca22
Posts: 6812
Joined: Sat Aug 18, 2012 2:33 pm

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 12:49 pm

thagrol wrote:
Sat Aug 28, 2021 12:47 pm
I'm in the process of doing an update so will investigate.

Can you confirm which OS you have running on both Pi and whether full or lite?

I suspect some of your network problems may be due to you using udev for configuration rather than dhcpcd or /etc/network/interfaces

I've no idea why

Code: Select all

echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
did not work (unless you did not reboot the 400 or restart the service)and I'm surprised that

Code: Select all

sudo tee /proc/sys/net/ipv4/ip_forward
was needed only once as /proc is a virtual file system recreated on each boot. Unless, again, you have yet to reboot the 400.

The quick and dirty fix for those commands that you have found that need to be run at boot would be to add them to /etc/rc.local (above the exit 0 line).
the tee into /proc saves you from having to do a reboot

User avatar
thagrol
Posts: 8171
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 12:50 pm

cleverca22 wrote:
Sat Aug 28, 2021 12:49 pm
thagrol wrote:
Sat Aug 28, 2021 12:47 pm
I'm in the process of doing an update so will investigate.

Can you confirm which OS you have running on both Pi and whether full or lite?

I suspect some of your network problems may be due to you using udev for configuration rather than dhcpcd or /etc/network/interfaces

I've no idea why

Code: Select all

echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
did not work (unless you did not reboot the 400 or restart the service)and I'm surprised that

Code: Select all

sudo tee /proc/sys/net/ipv4/ip_forward
was needed only once as /proc is a virtual file system recreated on each boot. Unless, again, you have yet to reboot the 400.

The quick and dirty fix for those commands that you have found that need to be run at boot would be to add them to /etc/rc.local (above the exit 0 line).
the tee into /proc saves you from having to do a reboot
Sure but when you do reboot you lose it.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

cleverca22
Posts: 6812
Joined: Sat Aug 18, 2012 2:33 pm

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 12:50 pm

thagrol wrote:
Sat Aug 28, 2021 12:50 pm
Sure but when you do reboot you lose it.
which is why you also write to /etc/sysctl.d, that handles what happens after reboot

User avatar
HermannSW
Posts: 5418
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 1:52 pm

thagrol wrote:
Sat Aug 28, 2021 12:47 pm
Can you confirm which OS you have running on both Pi and whether full or lite?
32bit PiOS Desktop on Pi400.
32bit PiOS lite on Pi0W.
https://hermann-sw.github.io/planar_graph_playground
https://stamm-wilbrandt.de/en#raspcatbt
https://github.com/Hermann-SW/memrun
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 5418
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sat Aug 28, 2021 2:01 pm

cleverca22 wrote:
Sat Aug 28, 2021 12:50 pm
thagrol wrote:
Sat Aug 28, 2021 12:50 pm
Sure but when you do reboot you lose it.
which is why you also write to /etc/sysctl.d, that handles what happens after reboot
Exactly that happened to me, I did both, and after reboot the routing.conf entry resulted in /proc entry being set:

Code: Select all

pi@raspberrypi400:~ $ cat /etc/sysctl.d/routing.conf
net.ipv4.ip_forward=1
pi@raspberrypi400:~ $ cat /proc/sys/net/ipv4/ip_forward
1
pi@raspberrypi400:~ $ 
https://hermann-sw.github.io/planar_graph_playground
https://stamm-wilbrandt.de/en#raspcatbt
https://github.com/Hermann-SW/memrun
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 5418
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sun Aug 29, 2021 7:35 am

thagrol wrote:
Sat Aug 28, 2021 12:47 pm
The quick and dirty fix for those commands that you have found that need to be run at boot would be to add them to /etc/rc.local (above the exit 0 line).
I did that successfully with Pi400, nothing is needed to be executed on the Pi400 side after booting to give Pi0W internet access:

Code: Select all

pi@raspberrypi400:~ $ tail -3 /etc/rc.local
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

exit 0
pi@raspberrypi400:~ $ 

I tried the same with "ip route" command on Pi0W, and that just did not work. Even with 5 second sleep command before the "ip route" command in /etc/rc.local.

So I tried to do all what is needed in udev rule. The very first command setting static ip address gets executed (otherwise "ssh pi@192.168.97.2" would fail on Pi400 -- I had that and needed micro sd card reader to fix the Pi0W card). And after deleting "/home/pi/id" and rebooting, that file gets written newly as shown below:

Code: Select all

pi@raspberrypi0W:~ $ tail -1 /etc/udev/rules.d/99-com.rules
SUBSYSTEM=="net",ACTION=="add",KERNEL=="usb0",RUN+="/home/pi/defroute"
pi@raspberrypi0W:~ $ cat defroute
#!/bin/bash
/sbin/ifconfig usb0 192.168.97.2 netmask 255.255.255.0
sleep 5
/sbin/ip route add default via 192.168.97.1 dev usb0
id > /home/pi/id
pi@raspberrypi0W:~ $ cat id
uid=0(root) gid=0(root) groups=0(root)
pi@raspberrypi0W:~ $ 

I have no idea why the "/sbin/ip" command doees not work there, even after 5 seconds. "ping 8.8.8.8" does not work, and there is no new default route:

Code: Select all

pi@raspberrypi0W:~ $ ip route
default dev usb0 scope link src 169.254.40.73 metric 202 
169.254.0.0/16 dev usb0 scope link src 169.254.40.73 metric 202 
192.168.4.0/24 dev wlan0 proto dhcp scope link src 192.168.4.1 metric 303 
192.168.97.0/24 dev usb0 proto kernel scope link src 192.168.97.2 
pi@raspberrypi0W:~ $ 

After executing that command manually, ping works:

Code: Select all

pi@raspberrypi0W:~ $ sudo /sbin/ip route add default via 192.168.97.1 dev usb0
pi@raspberrypi0W:~ $ ping -c 2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=112 time=23.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=112 time=18.4 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 18.413/20.871/23.330/2.462 ms
pi@raspberrypi0W:~ $ 

What is a working way to execute that command automatically after boot, so that it has the desired effect? rc.local as well as udev rule seem not to work (perhaps executed too early).
Last edited by HermannSW on Sun Aug 29, 2021 7:44 am, edited 1 time in total.
https://hermann-sw.github.io/planar_graph_playground
https://stamm-wilbrandt.de/en#raspcatbt
https://github.com/Hermann-SW/memrun
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

cleverca22
Posts: 6812
Joined: Sat Aug 18, 2012 2:33 pm

Re: STICKY: USB Ethernet Gadget A Beginner's Guide

Sun Aug 29, 2021 7:39 am

HermannSW wrote:
Sun Aug 29, 2021 7:35 am
I tried the same with "ip route" command on Pi0W, and that just did not work. Even with 5 second sleep command before the "ip route" command in /etc/rc.local.
if you run a dhcp server on the pi400, serving IP's to the usb0 interface, then you will get the route setup automatically, and dont have to do anything at all on the pi0 end

Return to “Beginners”