loftynz
Posts: 3
Joined: Sat Dec 09, 2017 10:38 pm

Internet connection sharing over USB wont work

Sat Dec 09, 2017 10:49 pm

Hi,

I have a pi zero v1.3 that im trying to control remotely from my laptop over usb as well as share internet connection.

Its setup with SSH, and i can login to the terminal fine using putty.
The instruction i read suggested I set a static ip.
i've tried sharing the internet connection from my network adapter page on windows, also tried bridging them, my laptop is connected to the internet via wifi.
'am i missing something obvious? should i try a dynamic ip?

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 1:21 am

To connect via USB you should use USB Gadget mode, which turns the Pi Zero into a USB Ethernet/RNDIS Gadget network adapter. You can then use Zeroconf to SSH into raspberrypi.local instead of using a static IP. You can share your Internet connection with the USB Ethernet gadget (ICS) and use VNC remote desktop if you want that.

To use USB Gadget mode start with a fresh Raspbian Stretch image.
Add this to the end of config.txt: dtoverlay=dwc2
Add this to the end of cmdline.txt: modules-load=dwc2,g_ether
Make sure you use a pure text editor on those files, and that cmdline.txt is one long single line (no breaks).

Finally, add a file named ssh (or ssh.txt) to the SD card. The contents don't matter. Its presence tells Raspbian to enable SSH.

All of these files are on the small FAT32 partition that is accessible to Windows/Mac computers.

That configures the Pi Zero to use USB Gadget mode, now to simplify your SSH/VNC connection you'll want the Zeroconf network service to resolve hostnames. You can install Apple's iTunes or Bonjour Printer Service, but if you don't want to install unnecessary stuff, use WinRAR or 7-Zip to extract the installer into a folder, and just install Bonjour.msi (32 bit) or Bonjour64.msi for the Zeroconf network service.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

loftynz
Posts: 3
Joined: Sat Dec 09, 2017 10:38 pm

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 5:27 am

Hi,

Yes before i even made my post I had....
edited both those text files and enabled ssh
installed bonjour, putty & RPD Desk on my windows 7 laptop
set raspberry pi's static ip address
successfully connected to the raspberry pi terminal remotely using putty
Run the if config and ping command.....

Code: Select all

[email protected]:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 104  bytes 9736 (9.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104  bytes 9736 (9.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.7.2  netmask 255.255.255.0  broadcast 192.168.7.255
        inet6 fe80::c0c6:ddff:fe0e:88e3  prefixlen 64  scopeid 0x20<link>
        ether c2:c6:dd:0e:88:e3  txqueuelen 1000  (Ethernet)
        RX packets 472  bytes 85770 (83.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 222  bytes 27450 (26.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[email protected]:~ $ sudo ping www.google.com
ping: www.google.com: Temporary failure in name resolution
[email protected]:~ $
I have tryed mucking with the network connection settings on my laptop, sharing/bridging the devices, obviously im making a connection but for some reason the internet connection sharing isnt working...

loftynz
Posts: 3
Joined: Sat Dec 09, 2017 10:38 pm

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 5:47 am

I just successfully got VNC remote desktop running! cool...
Now still need to work out this internet connection sharing stuff?? help?

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 9:06 am

So you have this in Device Manager?
Pi0_USB_Ethernet-RNDIS_Gadget.jpg
Pi0_USB_Ethernet-RNDIS_Gadget.jpg (68.65 KiB) Viewed 3252 times

If so, then you should just be able to go into your network adapter settings and turn on ICS.
ICS_Win10.jpg
ICS_Win10.jpg (30.55 KiB) Viewed 3252 times

Set whatever network connection you use for Internet access to share with the Pi0 Ethernet device.

And why did you set a static IP? That's likely your stumbling block.

I'll never understand the obsession with static IP addresses I see on this forum. Why does everyone try to do that?
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

n67
Posts: 839
Joined: Mon Oct 30, 2017 4:55 pm

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 1:57 pm

I'll never understand the obsession with static IP addresses I see on this forum. Why does everyone try to do that?
Because when things aren't working - for whatever reason(s) - setting a known IP address removes one variable from the equation, usually making debugging the real problem(s) easier.
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

User avatar
davidcoton
Posts: 3208
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 2:17 pm

n67 wrote:
Sun Dec 10, 2017 1:57 pm
I'll never understand the obsession with static IP addresses I see on this forum. Why does everyone try to do that?
Because when things aren't working - for whatever reason(s) - setting a known IP address removes one variable from the equation, usually making debugging the real problem(s) easier.
Or harder, if you choose the fixed address badly :( :roll:
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

fruitoftheloom
Posts: 17676
Joined: Tue Mar 25, 2014 12:40 pm

Re: Internet connection sharing over USB wont work

Sun Dec 10, 2017 2:25 pm

Windows Internet Connection Sharing always offers the same IP Address as it acts as a very basic DHCP Server.

Therefore Static IP Addressing is superfleous in whatever OS is running on the RPi SBC. Best to leave as a DHCP Client !
Adieu

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 9:57 am

n67 wrote:
Sun Dec 10, 2017 1:57 pm
Because when things aren't working - for whatever reason(s) - setting a known IP address removes one variable from the equation, usually making debugging the real problem(s) easier.
Except more often than not it's the cause of the problem.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

mattmiller
Posts: 1955
Joined: Thu Feb 05, 2015 11:25 pm

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 11:33 am

I tried playing with internet connection sharing (Pi to Win10 using USB) when the PiZero USB networking first came out and got it all working except for accessing the Internet

I spent a lot of time trying everything I could think of and find online and got nowhere

Basically, the Pi never ends up with a valid routable gateway address - I don't know whether its a Pi/Raspbian issue or a Windows ICS one but never got it working and never seen a post from anyone else who has either :(

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

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 1:17 pm

fruitoftheloom wrote:
Sun Dec 10, 2017 2:25 pm
Windows Internet Connection Sharing always offers the same IP Address as it acts as a very basic DHCP Server.
But unless you specify MAC addresses when loading g_ether (host_addr and dev_addr parameters) the MAC addresses are randomly generated each time g_ether is loaded so you may be getting a new IP address every time.
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

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

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 1:22 pm

Try using a bridge rather than ICS. That way the pi should get its config from your router.

For example https://www.windowscentral.com/how-set- ... windows-10
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 7:13 pm

mattmiller wrote:
Mon Dec 11, 2017 11:33 am
- I don't know whether its a Pi/Raspbian issue or a Windows ICS one but never got it working and never seen a post from anyone else who has either :(
Sure you have. It works for me with my Pi0 in USB Gadget mode and my Win10 notebook.

Pi Zero v1.3 running Raspbian Stretch 2017-11-29 in USB Gadget mode.
Connected to a Lenovo Yoga 2 Pro running Win10 Fall Creators Update with a micro-USB cable.
Pi0_USB_Gadget_mode_ICS.jpg
Pi0_USB_Gadget_mode_ICS.jpg (167.4 KiB) Viewed 3034 times
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

mattmiller
Posts: 1955
Joined: Thu Feb 05, 2015 11:25 pm

Re: Internet connection sharing over USB wont work

Mon Dec 11, 2017 8:20 pm

1st time i've seen/heard of it working (AFAICR)

Could you post the output of ifconfig from your Pi

Did it just automagically work for you or can you remember having to invoke special commands?

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Tue Dec 12, 2017 12:23 am

mattmiller wrote:
Mon Dec 11, 2017 8:20 pm
1st time i've seen/heard of it working (AFAICR)

Could you post the output of ifconfig from your Pi

Did it just automagically work for you or can you remember having to invoke special commands?

Code: Select all

~$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 9  bytes 524 (524.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9  bytes 524 (524.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.49  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::ee2a:bfb1:a81f:621f  prefixlen 64  scopeid 0x20<link>
        ether 1a:2b:3c:4d:5e:6f  txqueuelen 1000  (Ethernet)
        RX packets 703  bytes 156046 (152.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 209  bytes 33612 (32.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
What I did was posted above in the first reply to this thread, and it did "automagically" work for me the first time. I did have to disable and reenable ICS after rebooting, which apparently was because the Pi0 USB Ethernet Gadget does not have a fixed MAC address (not surprising since it's a virtual device). So the only other thing I have done that I forgot to mention above was to add a fixed MAC address to my Pi0 Gadget.

Code: Select all

sudo nano /etc/modprobe.d/g_ether.conf
options g_ether dev_addr=xx:xx:xx:xx:xx:xx
Replace xx with any hexadecimal numbers that don't match other MAC addresses on your network.

Note that ICS sometimes takes awhile to work. If you have just booted and have no Internet, give it a minute or so and try again. And your Windows Ethernet Gadget will always show "No internet" even when it's working on the Pi0 end.

I just ran through it again with a freshly imaged card to double check what I posted above, and it worked fine. I just edited the 2 files, added the ssh file, plugged the card into my Pi0, connected the micro-USB able to boot the little Pi0, and used PuTTY to connect to [email protected] (I already have Bonjour/Zeroconf installed). From there I was able to configure things, add users, update/upgrade, etc.

If you are going to reboot the Pi0 USB Gadget and have not given it a fixed MAC address, just turn off ICS when you reboot, and after the USB Ethernet gadget shows up in network connections again, turn ICS back on.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

mattmiller
Posts: 1955
Joined: Thu Feb 05, 2015 11:25 pm

Re: Internet connection sharing over USB wont work

Tue Dec 12, 2017 9:48 am

Try using a bridge rather than ICS. That way the pi should get its config from your router.
Yippee - finally got the PiZero able to accessing T'internet - thanks for that tip
(I still seem to be able to browse from my PC even though I didn't set a static IP as per the instructions but I'll watch out and see if that carries on working)

@HawaiiianPi

one problem I have when messing around with ICS is that I can set it but then if I try to swtich it off - my network adaptor settings window becomes unresponsive and I have to reboot to get control of it again

As you can imagine - this slows up testing things out :(

I'm seeing some stuff via Google last implies that some routers stop ICS type traffic (e.g packets in a different subnet) and I'm wondering if that is causing me not to be able to route out from the PiZero

I'm going to configure a static MAC address and see if that makes any diff to situation

mattmiller
Posts: 1955
Joined: Thu Feb 05, 2015 11:25 pm

Re: Internet connection sharing over USB wont work

Tue Dec 12, 2017 11:14 am

I tried setting static MAC address (while in bridging mode on my PC) and the settings

Code: Select all

sudo nano /etc/modprobe.d/g_ether.conf
options g_ether dev_addr=xx:xx:xx:xx:xx:xx
just wouldn't take (with proper hex digits)

I found an article that suggested doing this
To get a static Mac address, so that a host computer can assign a static IP, add:

g_ether.dev_addr=5a:77:1e:af:8e:9e g_ether.host_addr=72:8d:1f:c4:e8:ca
to the end of /boot/cmdline.txt
and that worked - repeated re-booting of my PiZero gave same MAC

So I tried again to use ICS and now I can access T'internet from my PiZero :)

(although I've had to reboot my PC and disable/re-enable ICS)

PS It doesn't seem 100% reliable to reconnect if I unplug and plug it back in - sometimes the RNDIS adapter disappears completely but at least it works some of the time :)

mattmiller
Posts: 1955
Joined: Thu Feb 05, 2015 11:25 pm

Re: Internet connection sharing over USB wont work

Tue Dec 12, 2017 11:31 am

And now its survived 5 unplugging/plugging without failure :)

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

Re: Internet connection sharing over USB wont work

Tue Dec 12, 2017 1:28 pm

Regarding fixed MAC addresses, I've got a script here https://github.com/thagrol/usb-gadget/b ... xed_mac.py that generates MAC address from the PI's serial number and loads g_ether.

Remove any references to g_ether from cmdline.txt, modprobe.d, /etc/modules etc. and call as root at the end of the boot sequence e.g. from rc.local

You need getserial.py from the same git repository too and both files mustbe in the same directory.
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

JQW
Posts: 1
Joined: Thu May 17, 2018 6:43 pm

Re: Internet connection sharing over USB wont work

Sat Jun 09, 2018 8:43 pm

I've have major problems getting Internet Connection sharing to share my laptop's WiFi connections to a Pi Zero in gadget mode.. I've only managed to get it to work reliably when using the WiFi network in my local public library - elsewhere it works occasionally. Disabling and re-enabling the connection occasionally fixed the problem, but not enough to be a reliable solution.

However this week I've discovered a fix. If I disable sharing, then share WiFi over the laptop's built-in Ethernet adaptor, disable that, and then share the Pi Zero's virtual Ethernet port, it works every time.

I suspect doing this clears something cache within the Windows network subsystem.

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Internet connection sharing over USB wont work

Sat Jun 09, 2018 11:53 pm

JQW wrote:
Sat Jun 09, 2018 8:43 pm
I've have major problems getting Internet Connection sharing to share my laptop's WiFi connections to a Pi Zero in gadget mode.
Have you configured your Pi Zero USB Ethernet Gadget with a fixed MAC address?

If not, then each time you boot the Pi0 gadget it will have a different MAC address, and ICS will have to be disabled and re-enabled to re-establish sharing (turn off ICS before booting the Pi0 gadget, then turn it back on after the USB Ethernet gadget shows up in Device Manager). There are some earlier posts in this thread about configuring a fixed MAC address, so do that if you want ICS to survive reboots.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

ejolson
Posts: 2050
Joined: Tue Mar 18, 2014 11:47 am

Re: Internet connection sharing over USB wont work

Sat Oct 20, 2018 5:56 pm

I understand that bridging is an alternative to setting up ICS. When I try to add the USB Ethernet device to a bridge on Windows I get "an unexpected error occurred." I know it is possible to bridge Ethernet gadgets using a Linux host. Is it possible to do the same on Windows? Has anyone done this?

Return to “Troubleshooting”