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
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
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!
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'
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
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!