Out-of-the-box Bone USB networking via IP masquerading

I’ve been having some fun playing with the Bone lately. It’s neat how you can attach it via the USB (and only USB) to a host computer and have the FAT partition mount on the post computer (Linux, Mac and Win7!). Then, one you eject the device a network connection between the Bone and the host appears.

The one thing missing is that the Bone can only talk to the host computer, not the rest of Internet land. Below is a script I’m developing, that’s run on the host, to give the Bone access to the Internet via IP masquerading through the host. You can also get the current version here [1].

I’ve tested it on a couple of Ubuntu 10.04 installs and it works. I’m open for suggestions for improvement.

My question is: How do I do the same with a Mac or Windows host?

–Mark

[1] git://github.com/MarkAYoder/BeagleBoard-exercises.git

#!/bin/bash

These are the commands to run on the host to setup IP masquerading so the Beagle

can access the Internet through the USB connection.

Inspired by Thoughts: Internet over USB-OTG on BeagleBoard using NAT

hostAddr=192.168.7.1
beagleAddr=192.168.7.2
ip_forward=/proc/sys/net/ipv4/ip_forward

if [ cat $ip_forward == 0 ]
then
echo “You need to set IP forwarding. Edit /etc/sysctl.conf using:”
echo “$ sudo gedit /etc/sysctl.conf”
echo "and uncomment the line “net.ipv4.ip_forward=1"”
echo “to enable forwarding of packets. Then run the following:”
echo “$ sudo sysctl -p”
exit 1
else
echo “IP forwarding is set.”
fi

Setup IP masquerading on the host

sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -o eth0 -j MASQUERADE

Check to see what nameservers the host is using and copy these to the same

file on the Beagle

This makes it so you can connect to the Beagle without using your password.

ssh-copy-id root@$beagleAddr

Save the /etc/resolv.conf on the Beagle in case we mess things up.

ssh root@$beagleAddr “mv -n /etc/resolv.conf /etc/resolv.conf.orig”

Copy the resolv.conf file to the Beagle. Now the Beagle will use the

same name servers as the host.

scp /etc/resolv.conf root@$beagleAddr:/etc

Tell the beagle to use the host as the gateway.

ssh root@$beagleAddr “/sbin/route add default gw $hostAddr”

Thanks for this great example. Do you have plans to put similar
instructions on the eLinux wiki? I'm just wondering if I should put a
link to this post in the G+ feed or wait for some other link.

Thanks to looking at this, I went through the process of figuring out
how to do the same thing with a Mac host. It turns out to be pretty
simple, but the BeagleBone acting as a DHCP host on the
Ethernet-over-USB solution will seem at first to work against you
(though it is actually mostly irrelevant). The solution is to turn on
Internet Sharing in the Preferences pane, then use the serial
connection to issue a 'udhcpc -i usb0' to instruct the BeagleBone to
request its network connection information from the Mac. Thanks for
the encouragement to figure this out!

I've been having some fun playing with the Bone lately. It's neat how you
can attach it via the USB (and only USB) to a host computer and have the FAT
partition mount on the post computer (Linux, Mac and Win7!). Then, one you
eject the device a network connection between the Bone and the host appears.

The one thing missing is that the Bone can only talk to the host computer,
not the rest of Internet land. Below is a script I'm developing, that's run
on the host, to give the Bone access to the Internet via IP masquerading
through the host. You can also get the current version here [1].

I've tested it on a couple of Ubuntu 10.04 installs and it works. I'm open
for suggestions for improvement.

My question is: How do I do the same with a Mac or Windows host?

Here is the video showing how to do it on a Mac:

Yes, instructions are now on the eLinux wiki [1].

I had my Bone talking to the world via USB through at Mac yesterday, but I’m unable to make it work today. The udhcpc -i usb0 command keeps saying Sending discover… like it’s not discovering anything. I’ve doubled checked settings, rebooted (both Bone and Mac) and it’s still not discovering. Any suggestions?

I’m also looking for instructions on making this work with Windows. I can see the USB network come up on both sides, but I can’t even ping from one to the other. That is beagle$ ping 192.168.7.1 and host$ ping 192.168.7.1 both return nothing.

Any suggestions?

–Mark

[1] http://elinux.org/index.php?title=EBC_Exercise_02_Out-of-the-Box,_Bone

Yes, instructions are now on the eLinux wiki [1].

I had my Bone talking to the world via USB through at Mac yesterday, but I’m unable to make it work today. The udhcpc -i usb0 command keeps saying Sending discover… like it’s not discovering anything. I’ve doubled checked settings, rebooted (both Bone and Mac) and it’s still not discovering. Any suggestions?

I’m also looking for instructions on making this work with Windows. I can see the USB network come up on both sides, but I can’t even ping from one to the other. That is beagle$ ping 192.168.7.1 and host$ ping 192.168.7.1 both return nothing.

Any suggestions?

What is the output of ‘ifconfig’? Can you please provide serial logs?

Can you provide screen captures of your settings on the Mac? Did you watch the video?

What are serial logs?

Screen captures Network settings, Sharing

Yes, I’ve watched the video. It was gripping. I’ve watched it several times!

ifconfig on Mac

ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether b8:8d:12:19:7e:0c
inet6 fe80::ba8d:12ff:fe19:7e0c%en0 prefixlen 64 scopeid 0x4
inet 137.112.123.235 netmask 0xffffff00 broadcast 137.112.123.255
media: autoselect
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
ether 0a:8d:12:19:7e:0c
media: autoselect
status: inactive
en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether d4:94:a1:91:99:49
inet6 fe80::d694:a1ff:fe91:9949%en3 prefixlen 64 scopeid 0x6
inet 192.168.7.1 netmask 0xfffffffc broadcast 192.168.7.3
media: autoselect (10baseT/UTP )
status: active

ifconfig on Bone

ifconfig
eth0 Link encap:Ethernet HWaddr D4:94:A1:91:CD:49
UP BROADCAST 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)
Interrupt:40

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:464 (464.0 B) TX bytes:464 (464.0 B)

usb0 Link encap:Ethernet HWaddr 7E:8D:AC:63:2E:BA
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:98 errors:0 dropped:0 overruns:0 frame:0
TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:22464 (21.9 KiB) TX bytes:6903 (6.7 KiB)

This was all working nicely util the switch to connman. Editing /etc/roslv.conf doesn’t make the DNS work anymore.

Anyone know how to get connman to use the right DNS?

–Mark

This was all working nicely util the switch to connman. Editing
/etc/roslv.conf doesn't make the DNS work anymore.

Anyone know how to get connman to use the right DNS?

It still works for me. Are you sure the issue is DNS?

I've found a more practical solution for me for getting http and https
access that utilizes a web proxy.

I added to my ~/.ssh/config on my Mac host:

Host beaglebone*.local 192.168.7.2
    User root
    UserKnownHostsFile /dev/null
IdentityFile no
    StrictHostKeyChecking no
    ForwardX11 yes
    RemoteForward 8000 my.web.proxy:80

Now, when I ssh in, I do the following:

export http_proxy=localhost:8000
export https_proxy=localhost:8000

That then enables me to run things like 'npm install' and 'opkg update'.

Hope this helps some.

The Internet connection sharing on the OSX GUI doesn't work anymore, so if
I want to do that, I use this script on my Mac host:

GATEWAY_DEV=en0
HOST_DEV=en1
HOST_ADDR=192.168.7.1
BEAGLE_ADDR=192.168.7.2

sudo /sbin/ifconfig $HOST_DEV down
sudo /sbin/ifconfig bridge0 create
sudo /sbin/ifconfig bridge0 up
sudo /sbin/ifconfig bridge0 addm $GATEWAY_DEV
sudo /sbin/ifconfig bridge0 $HOST_ADDR
sudo /sbin/route add default -interface bridge0 -ifscope bridge0 -cloning
sudo /usr/sbin/sysctl -w net.inet.ip.forwarding=1
sudo /sbin/ipfw add 100 divert natd ip from any to any via $GATEWAY_DEV
sudo /usr/sbin/natd -interface $GATEWAY_DEV -use_sockets -same_ports
-unregistered_only -dynamic -clamp_mss -enable_natportmap
-natportmap_interface $HOST_DEV

However, I've seen it have problems with larger packets that causes
connections to simply hang. The ssh socket forwarding doesn't have that
same issue.

My host is running Ubuntu 12.04. When I run the script below I’m able to ssh to my bone from the host via
ssh -XC 192.168.7.2

On the bone I can:
bone$ ping 173.194.46.37
PING 173.194.46.37 (173.194.46.37) 56(84) bytes of data.
64 bytes from 173.194.46.37: icmp_req=1 ttl=54 time=372 ms
64 bytes from 173.194.46.37: icmp_req=2 ttl=54 time=381 ms
64 bytes from 173.194.46.37: icmp_req=3 ttl=54 time=250 ms

But I can’t:
bone$ ping google.com
ping: unknown host google.com

So I’m able to reach the outside world from by bone via the host, but DNS doesn’t appear to be working. This worked fine before switching to the new image with the 3.8 kernel and connman.

So how can I get the bone to use DNS under connman?

–Mark

#!/bin/bash

These are the commands to run on the host to setup IP masquerading so the Beagle

can access the Internet through the USB connection.

Inspired by Thoughts: Internet over USB-OTG on BeagleBoard using NAT

if [ $# -eq 0 ] ; then
echo “Usage: $0 interface (such as eth0 or wlan0)”
exit 1
fi

interface=$1
hostAddr=192.168.7.1
beagleAddr=192.168.7.2
ip_forward=/proc/sys/net/ipv4/ip_forward

if [ cat $ip_forward == 0 ]
then
echo “You need to set IP forwarding. Edit /etc/sysctl.conf using:”
echo “$ sudo gedit /etc/sysctl.conf”
echo "and uncomment the line “net.ipv4.ip_forward=1"”
echo “to enable forwarding of packets. Then run the following:”
echo “$ sudo sysctl -p”
exit 1
else
echo “IP forwarding is set on host.”
fi

Setup IP masquerading on the host

sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -o $interface -j MASQUERADE

Check to see what nameservers the host is using and copy these to the same

file on the Beagle

This makes it so you can connect to the Beagle without using your password.

ssh-copy-id root@$beagleAddr

Save the /etc/resolv.conf on the Beagle in case we mess things up.

ssh root@$beagleAddr “mv -n /etc/resolv.conf /etc/resolv.conf.orig”

Copy the resolv.conf file to the Beagle. Now the Beagle will use the

same name servers as the host.

cat - << EOF > /tmp/resolv.conf

This is installed by host.ipForward.sh on the host

Mark A. Yoder, 11-Sept-2012

nameserver 137.112.18.59
nameserver 137.112.5.28
nameserver 137.112.4.196
search rose-hulman.edu
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
scp /tmp/resolv.conf root@$beagleAddr:/etc

Tell the beagle to use the host as the gateway.

ssh root@$beagleAddr “/sbin/route add default gw $hostAddr”