Difference between revisions of "BBB Internet over the USB cable"

From Klaus' wiki
Jump to: navigation, search
(Prepare the BBB)
(Prepare the BBB)
Line 70: Line 70:
  
 
==Prepare the BBB==
 
==Prepare the BBB==
As root on the BBB, in the '''/root/bin''' directory, create a file named internetOverUSB and make it executable
+
As root on the BBB, in the '''/root/bin''' directory, create a file named '''internetOverUSB''' and make it executable
 
<source lang=bash>
 
<source lang=bash>
 
#!/bin/bash
 
#!/bin/bash

Revision as of 11:25, 23 February 2018

It is rather easy to get access to the whole internet over the USB interface cable provided that your laptop/PC has internet access.

Enabling masquerading

Masquerading is forwarding the Internet to the BBB over the "USB network".

If you're running Linux you can follow these instructions.

Centos / Fedora The manual way

NOTE: On Centos the Firewall graphical interface doesn't seem to work properly, which means that you have to modify a settings file instead. You can perform the same settings change on other Linuxes, i.e. Fedora and others, that run firewalld.

for Centos edit the /etc/firewalld/zones/public.xml

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="dhcpv6-client"/>
  <service name="ssh"/>
  <port protocol="tcp" port="22"/>
</zone>

add just before the </zone> this line:

  <masquerade/>

Then to reload the settings perform

$] systemctl restart firewalld.service

If you're running Windows Derrek Molloy has some advices on this page.

Debian/Mint

Flemming Christensen provided this guide to Debian/Mint - it may be working on other Debian based distributions like Ubuntu, etc.

To setup internet over usb from Linux Mint to BeagleBone Black "Debian OS" execute this on the BBB.

]$ sudo ufw disable
]$ sudo apt-get iptables
]$ sudo iptables -F “clean iptables rules”
]$/sbin/route add default gw 192.168.7.1
]$ echo "nameserver 8.8.8.8" >> /etc/resolv.conf

The last two lines are part of the script below.

On the Linux Mint host from which you want to route:

]$ sudo iptables -A POSTROUTING -t nat -j MASQUERADE
]$ sudo echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null

Now on the BBB:

]$ ping d.dk
]$ ping google.dk

If this dosen't work, try allowing this in the firewall via the terminal.

]$ sudo ufw allow 192.168.7.2/22

Prepare the BBB

As root on the BBB, in the /root/bin directory, create a file named internetOverUSB and make it executable

#!/bin/bash
# 
# Author : Klaus Kolle
#   Date : 2016 02 22
# Purpose: Establishing connection to the Internet
# and set the clock, which has no battery backup
#
 
echo "Starting the Internet-over-USB script"
 
## Add a default gateway 
/sbin/route add default gw 192.168.7.1
grep -q 8.8.8.8 /etc/resolv.conf
if [ "$?" -ne "0" ]; then
        echo "nameserver 8.8.8.8" >> /etc/resolv.conf
fi
 
## Test for network availability
while :
do
        ping -c 5 -w 10 192.168.7.1
        if [ $? -eq 0 ]; then
                break
        fi
done
 
## Now we should be ready to set the clock from the net
/usr/sbin/ntpdate -b -s -u dk.pool.ntp.org
date
echo "End of the settings script"

To make the file executable execute this command:

$] chmod u+x internetOverUSB

At first login on the BBB execute this script as root (or use sudo).

Automating the script

You may want to set this script up so it will be executed at boot time. In order to do this you'll have to setup a boot script in /etc/init.d - you may want to call it internetOverUSB. Enter ths into the script.

#! /bin/sh
 
### BEGIN INIT INFO
# Provides: InternetOverUSB
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Enables Internet over USB cable
# Description: Enables access to the Internet over the Internet connection 
# provided by the connected host
### END INIT INFO
case "$1" in
        start)
                sleep 20
                /root/bin/internetOverUSB
        ;;
        stop)
                #no-op
        ;;
        *)
                #no-op
        ;;
esac
 
exit 0

Now execute

$] chmod 755 /etc/init.d/internetOverUSB

The 20 seconds sleep is for the laptop being able to establish its network settings. May be adjusted to suit your OS and laptop specific needs.

Finally enable the script.

$] update-rc.d internetOverUSB defaults

Try to reboot and login again. Check that the date now is correct. If not debug your scripts.

Windows Challenges

If your host OS is Windows you may run into problems.

Sometimes Windows causes problems letting the network packages go all the way through to the Internet from the BBB via the Centos virtual PC.

You may try these advices in order to overcome the challenges.

First unplug your BBB.

Second Shut-off you virtual Centos.

Third go to VirtualBox settings for the virtual machine and select Network. Ensure that you use NAT as shown in this picture

VirtualBox.png

Fourth plug in your BBB and wait until it has booted completely. In VirtualBox settings switch to the USB settings and add by clicking on the +-button to the right your BeagleBone, which can have one of several names - for instance I've met Circuitco BBB and BeagleBoard.org BBB.

VirtualBox1.png

Finally unplug the BBB and reboot Windows. Then start the virtual Centos and when it is up running plug in the BBB and observe that it, after the booting sequence has completed, announces it self in the Centos virtual PC, i.e. the USB storage is available and the network interface is working.

Speed up the login process

Whenever a host tries to login on the BBB, the software running will try to lookup a hostname and an IP address using the DNS system. But sometimes, this can delay the login considerably. Fix it using this hint