Manual Usb Network And Websurfing


chris_c

Member
Joined
Jun 25, 2010
Messages
393
Age
56
when using opkg for example - doing it over a flaky wifi connection can be like stabbing yourself in the face with a rusty spoon! so I decided to stop being lazy and complete my usb scripts.

This example assumes the following

your router is capable of acting as a nameserver
the IP address of your router is 192.168.1.1
your desktop machine is running Linux (only tested with ubuntu but others should be identical)
your desktop machine is on a static IP address of 192.168.1.100
the Pandora is the only CDC usb device so appears as device usb0 on the desktop
You appreciate that the IPTABLES rules are potentially insecure (the desktop could potentially NAT for anything that could connect locally or through your routers firewall) - I leave it as an exercise for the reader to make it more secure - this is a quick and dirty get you working, fix it properly later job!

for simplicity I have set up the usb networking on a different sub net, its possible to share the same subnet but you need some extra steps frankly I can't see any reason to bother.

The first gotcha is if you are using the dreaded Network Manager on your desktop - it will interfere and drop connections for you and make multiple connections in its list - but here's the work round - the first time it auto connects edit the connection and in the IPv4 settings tab change the method to Link-Local Only - hopefully then it will leave you alone - why there isn't a black list for devices not to configure who knows!

I prefer to manually set up my connection and once you have this working you can should you choose use google to find out how to automagically(tm) implement the settings when you plug in a cable to the usb OTG port (It would be nice if future firmwares would ask for sub net and router IP's the first time OTG was plugged in and allow you to change these settings so the Pandora side at least was automagically(tm) set up)

first plug in a usb cable between the pandoras OTG usb port and your desktop (just a normal usb mini like on a usb HD not no fancy pants OTG connector or it won't work ;) )

run this script on your pandora
Code:
#!/bin/bash
sudo ifconfig usb0 down
sudo /etc/init.d/usb-gadget start
sudo ifconfig usb0 192.168.0.200 netmask 255.255.255.0 up
sudo route add -host 192.168.0.100 usb0
sudo route add default gw 192.168.0.100 usb0
sudo sh -c 'echo "nameserver 192.168.1.1" > /etc/resolv.conf'
the IP address 192.168.1.1 should be replaced with the local IP address of your router
at this point you'll have to use the Network manager work-a-round as its trying to get a dhcp connection and will soon drop the link - if it does drop the link save the link only changes and run the script again

This sets up your pandora as 192.168.0.200 and your desktop as 192.168.0.100 (as well as the desktops other LAN settings this is for usb0 only) - also if dropbear is running on your pandora 192.168.0.200 is the address you'll need for filezilla, ssh etc

before we can do all of that we need to run a script on the desktop
Code:
#!/bin/bash
sudo ifconfig usb0 192.168.0.100 netmask 255.255.255.0 up 
sudo route add -host 192.168.0.200 usb0

sudo sysctl -w net.ipv4.ip_forward=1

sudo /sbin/iptables -A INPUT -s 192.168.0.200 -d 192.168.0.100 -j ACCEPT

sudo /sbin/iptables -t nat -A POSTROUTING -s 192.168.0.200 -o eth0 -j MASQUERADE
sudo /sbin/iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo /sbin/iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT
notice here that eth0 is the device that's connected to your router

hopefully now not only can you ping external IP addresses but also ping google.com will work and not only that but surfing the net with wifi disabled will work and not only work but be *blisteringly* fast!

good luck!

NB edited the PC script to fix it! ssh now works as well as surfing - sorry for the inconvenience!
 
sebt3 said:
Hi chris_c,

Why not using your OS feature ?
Edit /etc/network/interfaces as you please (using pre_up and post_up scripts as much as need)

Then "ifup usb0" will bring the interface up :)

have a good day,
SebT3
I want to leave all the system scripts alone I don't wand to be managing settings on 3-4 different boot SD cards and I'd rather do it this way

I have to be honest and point out although this works great for surfing on the pandora I seem to have broken SSH access somehow so I need to look into this!

-ok it works now the PC script above has been edited...
 
Last edited by a moderator:
Thanks, Chris.

After enabling the kernel-option "Device Drivers -> Network device support -> USB Network Adapters -> Multi-purpose USB Networking Framework" i quickly managed to establish a connection between my Pandora and my GentooPC. SSH works nicely, which was my major interest in this topic. Currently i am struggling with iptables out of curiosity, but for some reason pinging my router-ip-number from my Pandora does not work yet. I'll try some more. ;)

Edit: Did a transfertest: ~1,7MB/s with scp while transfering the pandora-rootfs-tarball
Edit2: Got internet-sharing running now, too. Thanks again.
 
Lomaxx said:
Thanks, Chris.

After enabling the kernel-option "Device Drivers -> Network device support -> USB Network Adapters -> Multi-purpose USB Networking Framework" i quickly managed to establish a connection between my Pandora and my GentooPC. SSH works nicely, which was my major interest in this topic. Currently i am struggling with iptables out of curiosity, but for some reason pinging my router-ip-number from my Pandora does not work yet. I'll try some more. ;)

Edit: Did a transfertest: ~1,7MB/s with scp while transfering the pandora-rootfs-tarball
Edit2: Got internet-sharing running now, too. Thanks again.
:D it was worth posting then!
 
Last edited by a moderator:
chris_c said:
sebt3 said:
Hi chris_c,

Why not using your OS feature ?
Edit /etc/network/interfaces as you please (using pre_up and post_up scripts as much as need)

Then "ifup usb0" will bring the interface up :)

have a good day,
SebT3
I want to leave all the system scripts alone I don't wand to be managing settings on 3-4 different boot SD cards and I'd rather do it this way

I have to be honest and point out although this works great for surfing on the pandora I seem to have broken SSH access somehow so I need to look into this!

-ok it works now the PC script above has been edited...

Another option is to leave /etc/network/interfaces alone and just create an interfaces file on your SD card.

Then run

Code:
ifup -i /path/to/my/interfaces usb0
 
Last edited by a moderator:
Hello,

and sorry to bring up this old thread again. I'm one unlucky guy who isn't able to set up a USB network with my Pandora. Through the USB network I just want my Pandora using the Internet, nothing more.

There're different approaches to set up a USB network but none worked for me. I've almost not any knowledge about network issues so to me this is a pure nightmare.

This is my starting basis:
The Pandora with USB networking enabled and plugged into my PC which is running a Knoppix Live CD. My PC's internet connection is a cable connection. I can see my cable network and connection 'Auto eth0' and the Pandora's network (Linux 2.6.27.46 [...] CDC Composite Gadget) that's not connected. I've no router and my static IP is in the range 178.25.x.x.

I was never able to connect the Pandora to my PC whatever I tried but sometimes to could bring up the 'Auto usb0' connection. While trying to connect I ended up with several errors all the time. Either "Connection timed out" or "No route to host", also "Network is unreachable" and "Connection refused".

What I believe to know is that all IP addresses I allocate in my network have to start with 178.25.x.x because this is the range of my own IP, right? I could cry to heaven why there's no secure way to get a USB network to function properly. So many ways and so different requirements to achieve it. This makes my crazy!

Well, I also tried the method by chris_c here. At least I could input all the lines without getting any errors xD
All the 192.168.0.x IP's I replaced by my range of 178.25.0.x. Finally I checked if I can see the usb0 interface as well as on the Pandora and on the PC. But nothing happened. No connection. The only difference to all my other attempts was that the web browser on the Pandora needed about 30 seconds until it says that any webpage cannot be displayed. Up to now I got this message promptly.

BTW: I also disabled the Knoppix's firewall to ensure it is not blocking the connection.

Any further help please?

Thanks.
 
Back
Top