Homepage Wiki Forum Buy

Pseudo Network with USB

From GNUBLIN

severity (level) requirement Gnublin family
Gnublin logo advanced.png Kernel compile, Toolchain Alle

Contents

GNUBLIN as a virtual USB network device

Preparations:

  • Disconnect GNUBLIN from external voltage.
  • Change jumper positions from "USB OTG PWR" and "USB OTG ID" to "Device". You can have a look for the jumpers here
  • Connect both USB wires between GNUBLIN and your host PC and gnublin should boot.

Load the driver

On Gnublin

root@gnublin:~# modprobe g_ether g_ether gadget: using random self ethernet address g_ether gadget: using random host ethernet address usb0: MAC 2e:dd:9a:ed:d2:48 usb0: HOST MAC 56:e5:4d:4b:18:84 g_ether gadget: Ethernet Gadget, version: Memorial Day 2008 g_ether gadget: g_ether ready fsl-usb2-udc: bind to driver g_ether root@armv5te:~# g_ether gadget: high speed config #1: CDC Ethernet (ECM)

Assign IP adress

On Gnublin:

root@gnublin:~# ifconfig usb0 10.0.0.1 up

and controll it:

root@gnublin:~# ifconfig lo ... usb0 Link encap:Ethernet HWaddr 2E:DD:9A:ED:D2:48 inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


Enter on host PC: Hint:Don't load g_ether

On OpenSuse 12.1 usb0 will be created only after you have assigned the IP.

hhoegl@aspire1:~$ sudo ifconfig ... usb0 Link encap:Ethernet HWaddr 56:e5:4d:4b:18:84 inet6 addr: fe80::54e5:4dff:fe4b:1884/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:2052 (2.0 KB) ...

Assign IP:

sudo ifconfig usb0 10.0.0.2 up

Check:

hhoegl@aspire1:~$ sudo ifconfig ... usb0 Link encap:Ethernet HWaddr 56:e5:4d:4b:18:84 inet addr:10.0.0.2 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::54e5:4dff:fe4b:1884/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:4723 (4.7 KB) ...

Check connection with ping:

hhoegl@aspire1:~$ ping 10.0.0.2 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.954 ms 64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.815 ms 64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.812 ms ...



User the internet connection from host PC

On gnublin add the host PC as default gateway:

route add default gw 10.0.0.2

On host PC make this release:

sudo su -c "echo 1 > /proc/sys/net/ipv4/ip_forward && iptables -P FORWARD ACCEPT && iptables -A POSTROUTING -t nat -j MASQUERADE -s 10.0.0.0/24"

Start webserver on GNUBLIN

On Gnublin

root@gnublin:~# bash /home/root/lighttpd-init.sh

The file lighttpd-init.sh contains:

        #!/bin/sh

        if [ ! -d /var/log/lighttpd ]
        then
           mkdir /var/log/lighttpd
           chmod 777 /var/log/lighttpd/
           touch /var/log/lighttpd/error.log
        fi
        chmod 666 /var/log/lighttpd/error.log
        /etc/init.d/lighttpd start

On a PC start a webbrowser and connect to URL:

http://10.11.12.1


After that, the message "Hello, world" should be displayed :

ssh connection from PC to Gnublin

On the PC connect to the SSH server of GNUBLIN:

hhoegl@aspire1:~$ ssh root@10.11.12.1 The authenticity of host '10.11.12.1 (10.11.12.1)' can't be established. RSA key fingerprint is af:0a:d9:9b:f2:ce:5d:9d:d2:6d:3b:1a:b5:4a:c1:0f. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.11.12.1' (RSA) to the list of known hosts. root@10.11.12.1's password: root@armv5te:~#


In order to make this work, dropbear or openssh has to run on GNUBLIN. Openssh is running on default. If neccessary, start with "/etc/init.d/dropbear start".


It's even possible to do that in the other direction (ssh deamon has to run on host PC):

On Gnublin:

root@gnublin:~# ssh hhoegl@10.11.12.2 Host '10.11.12.2' is not in the trusted hosts file. (fingerprint md5 47:15:5c:61:aa:d6:cb:22:ff:24:3a:ff:84:98:6a:37) Do you want to continue connecting? (y/n) y hhoegl@10.11.12.2's password: Linux aspire1 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux Ubuntu 10.04.3 LTS Welcome to Ubuntu! * Documentation: https://help.ubuntu.com/ Your CPU appears to be lacking expected security protections. Please check your BIOS settings, or for more information, run: /usr/bin/check-bios-nx --verbose Last login: Thu Feb 2 22:01:05 2012 from localhost hhoegl@aspire1:~$
In other languages