BeagleBone Black Persistent USB Internet Connection

In a previous blog post I wrote about a little experiment I did with a BeagleBone Black and a Neato LIDAR. Eventually I plan to use these parts to build an autonomous wheeled robot, but I realized that before I go much further it would be a good idea for the BeagleBone Black to have internet connectivity, ideally wireless. This will not only greatly simplify the process of installing various software packages, but it will also allow me to SSH to the BeagleBone Black over my local WiFi network.

BeagleBone Black connected to the internet via USB through my laptop's internet connection

In this blog post, I’m going to keep it simple and just explain how I setup the BeagleBone Black to share my laptop’s internet connection over USB. This makes it easier to setup a wireless internet connection, which will be the topic of another blog post.

First Things First

First of all, you will need to make sure that you can establish an SSH connection to the BeagleBone Black. If you haven’t already done so, you can find instructions for SSH Setup on the Adafruit website.

I have only tested this setup on a BeagleBone Black running the Debian operating system, so you may want to do the same if you are going to follow the steps that I took. The latest images of the Debian OS can be found here. The image that I used was dated 2014-04-23. To check the version installed, run the following command on the BeagleBone Black.

cat /boot/uboot/ID.txt

Setup Internet Sharing on Windows

My laptop is running Windows 8.1, so I have not taken the time to find the steps needed to setup internet sharing for any other operating systems.

For Windows:

  • Open the control panel, and search for “network connections” in the search box. Click “View Network Connections” in the results.
  • Right-click the internet connection to share with the BeagleBone Black and select Properties. Navigate to the Sharing tab.
  • Select the option to “Allow other network users to connect through this computer’s Internet connection”.
  • Select the BeagleBone Black’s network connection from the dropdown and then click OK.
  • Now go back to Network Connections and right click the BeagleBone Black’s network connection, and select Properties.
  • Click “Internet Protocol Version 4 (TCP/IPv4)” in the list and select Properties.
  • Select the options to “Obtain an IP address automatically” and “Obtain DNS server address automatically”, and click OK.

Setup Internet Sharing on BeagleBone Black

Through an SSH connection to the BeagleBone Black, run the following commands.

route add default gw 192.168.7.1
echo "nameserver 8.8.8.8" >> /etc/resolv.conf

Test the internet connection by pinging a website: ping stackoverflow.com

If that worked, congratulations! Your BeagleBone Black now has internet access.

Persisting the Internet Connection Settings

There is one last step to complete so that the internet connection works even after the device is rebooted.

Run this command to edit one of the scripts that runs when the device boots.

nano /opt/scripts/boot/am335x_evm.sh

Scroll down until you see the following lines.

/sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252
/usr/sbin/udhcpd -S /etc/udhcpd.conf

Immediately after those lines, add the following line.

/sbin/route add default gw 192.168.7.1 metric 1

Be sure to save the file before closing it.

Conclusion

That’s all there is to it. For further reading on this topic, see this blog post and this article. In a later blog post I will explain how to setup the BeagleBone Black with wireless network connectivity.

3 Comments


  1. Hi,
    I’m trying to change the kernel of my BeagleBone Black through tftp server. Also, I have connected the serial and open a terminal into uBoot.
    But, at uBoot, internet usb connection is not enabled, so I can share any information through it, nor kernel neither another file.
    Then, I restart the BBB as usual, but once ‘am335x_evm.sh’ is opened, there is no lines with “/sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252” or similar.
    So, I can’t establish any communication nor upload the new kernel to BBB.
    Could you tell me any hint to go forward, please?
    KR!

    Reply

  2. Hi Alex,

    I followed up the instructions you set in your blog on a Debian Distribution dated back to the 23 of April 2014 and it worked nicely. When i downloaded another Linux Distro (Debian image updated on the 12th of November 2015), i couldnt find the scripts shown below when i wanted to add a permanet Internet connection;
    /sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252
    /usr/sbin/udhcpd -S /etc/udhcpd.conf
    Where do i add that new gateway script?

    Kind Regards,

    Tinashe

    Reply

  3. did at /opt/scripts/boot/autoconfigure_usb0.sh
    use at same line

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *