STICKY: USB Ethernet Gadget A Beginner's Guide
2022-04-21: Nwe version:
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...
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
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
Re: USB Ethernet Gadget A Beginner's Guide
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
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
-
- Posts: 2331
- Joined: Sat Nov 09, 2019 12:14 pm
Re: USB Ethernet Gadget A Beginner's Guide
Wouldn't that be Windows 100?Windows 10 works without an issue even with two Zeros.
Poster of inconvenient truths.
Back from a short, unplanned vacation. Did you miss me?
Back from a short, unplanned vacation. Did you miss me?
Re: USB Ethernet Gadget A Beginner's Guide
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.
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
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
Re: USB Ethernet Gadget A Beginner's Guide
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.
Re: USB Ethernet Gadget A Beginner's Guide
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
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
Re: USB Ethernet Gadget A Beginner's Guide
Thanks for your work on this. Looks very useful.
Moderator:. Would you make this a sticky please!
Phil
Moderator:. Would you make this a sticky please!
Phil
-
- Posts: 6984
- Joined: Sat Aug 18, 2012 2:33 pm
Re: USB Ethernet Gadget A Beginner's Guide
another option is to get it into the official docs: https://github.com/raspberrypi/documentationthagrol wrote: ↑Sun Mar 07, 2021 2:19 pmThank for clearing the chaff.mahjongg wrote: ↑Sun Mar 07, 2021 2:12 pmNO!
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...
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.
Re: USB Ethernet Gadget A Beginner's Guide
I image there would be some problems with that:cleverca22 wrote: ↑Sun Mar 07, 2021 2:22 pmanother option is to get it into the official docs: https://github.com/raspberrypi/documentation
- 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.
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
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
Re: USB Ethernet Gadget A Beginner's Guide
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.
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.
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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.
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.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
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
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
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
thagrol wrote: ↑Thu Apr 08, 2021 6:46 pmNope. 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.
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.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
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!
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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:
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
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
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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
No changes to the guide but new zip file attached.
https://github.com/thagrol/Guides
- Attachments
-
- ethernetgadget.zip
- (108.98 KiB) Downloaded 279 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
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
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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.
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
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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.
NPVery nice! Thanks again.
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
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
Re: STICKY: USB Ethernet Gadget A Beginner's 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
Code: Select all
pi@raspberrypi400:~ $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
1
pi@raspberrypi400:~ $
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://github.com/Hermann-SW/RSA_numbers_factored
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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 did not work (unless you did not reboot the 400 or restart the service)and I'm surprised that 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).
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
Code: Select all
sudo tee /proc/sys/net/ipv4/ip_forward
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
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
-
- Posts: 6984
- Joined: Sat Aug 18, 2012 2:33 pm
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
the tee into /proc saves you from having to do a rebootthagrol wrote: ↑Sat Aug 28, 2021 12:47 pmI'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 whydid not work (unless you did not reboot the 400 or restart the service)and I'm surprised thatCode: Select all
echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
was needed only once as /proc is a virtual file system recreated on each boot. Unless, again, you have yet to reboot the 400.Code: Select all
sudo tee /proc/sys/net/ipv4/ip_forward
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).
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
Sure but when you do reboot you lose it.cleverca22 wrote: ↑Sat Aug 28, 2021 12:49 pmthe tee into /proc saves you from having to do a rebootthagrol wrote: ↑Sat Aug 28, 2021 12:47 pmI'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 whydid not work (unless you did not reboot the 400 or restart the service)and I'm surprised thatCode: Select all
echo net.ipv4.ip_forward=1 | sudo tee /etc/sysctl.d/routing.conf
was needed only once as /proc is a virtual file system recreated on each boot. Unless, again, you have yet to reboot the 400.Code: Select all
sudo tee /proc/sys/net/ipv4/ip_forward
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
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
-
- Posts: 6984
- Joined: Sat Aug 18, 2012 2:33 pm
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
32bit PiOS Desktop on Pi400.
32bit PiOS lite on Pi0W.
https://github.com/Hermann-SW/RSA_numbers_factored
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
Exactly that happened to me, I did both, and after reboot the routing.conf entry resulted in /proc entry being set:cleverca22 wrote: ↑Sat Aug 28, 2021 12:50 pmwhich is why you also write to /etc/sysctl.d, that handles what happens after reboot
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://github.com/Hermann-SW/RSA_numbers_factored
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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://github.com/Hermann-SW/RSA_numbers_factored
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/Raspberry_camera.html
https://stamm-wilbrandt.de/
-
- Posts: 6984
- Joined: Sat Aug 18, 2012 2:33 pm
Re: STICKY: USB Ethernet Gadget A Beginner's Guide
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