Skip to content

Instantly share code, notes, and snippets.

@zankich
Last active April 1, 2019 10:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zankich/6e2522dcb93afb94abae to your computer and use it in GitHub Desktop.
Save zankich/6e2522dcb93afb94abae to your computer and use it in GitHub Desktop.
connect to your beaglebone black using the usb->ethernet and forward the internet from your host computer to the beaglebone black
#!/bin/bash
#
# run this script on your linux host computer to connect to the bbb and forward your internet.
# be sure to replace "enp0s20u1" with the appropriate usb device for your bbb, which can be found
# by doing an "ifconfig" on your host computer.
#
sudo -- sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
sudo ifconfig enp0s20u1 192.168.7.1 255.255.255.0
ssh root@192.168.7.2
#!/bin/bash
#
# run this script on your bbb to use the internet forwarded from your host linux computer
#
ROUTE=`route | grep 0.0.0.0 | wc -l`
if [ $ROUTE -eq 0 ]
then
sudo -- sh -c 'echo "nameserver 8.8.8.8" >> /etc/resolv.conf'
sudo /sbin/route add default gw 192.168.7.1
sudo ntpdate ntp.ubuntu.com
fi
@milesfrain
Copy link

Had some issues with a few of the lines in bbb_connect.sh
The iptables line sudo iptables -A POSTROUTING -t nat -j MASQUERADE stopped webpages from loading on my host machine. It seems like an outgoing interface is required to prevent the issue. For others following along, revert the setting with sudo iptables --table nat --flush.
The ifconfig line sudo ifconfig enp0s31f6 192.168.7.1 255.255.255.0 returned an SIOCSIFADDR: Invalid argument error. This line doesn't seem critical anyway, since 192.168.7.1 is already listed as my USB interface IP.
Some of the commands on this page worked a bit better for me.
My final script ended up being the following:

#!/bin/bash

# select correct interfaces from "ifconfig":
BBGW_IFACE=enp0s31f6 
# Ethernet
PC_IFACE=wlp4s0
# Wireless
#PC_IFACE=todo

sudo sysctl net.ipv4.ip_forward=1
sudo iptables --table nat --append POSTROUTING --out-interface $PC_IFACE -j MASQUERADE
sudo iptables --append FORWARD --in-interface $BBGW_IFACE -j ACCEPT

In the internet_sharing.sh script, the ntpdate line doesn't seem necessary anymore on the latest image (debian 9.5). ntpdate was replaced by ntpd, and then by timedatectl. Running timedatectl on the beaglebone shows the time in-sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment