Difference between revisions of "PB:Get an Internet connection"

From Klaus' wiki
Jump to: navigation, search
(Preparing the PocketBeagle for connecting the Internet)
(Automate the network configurations)
Line 69: Line 69:
===Automate the network configurations===
===Automate the network configurations===
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.
If /root/bin directory doesn't exists execute
<source lang=bash>
]$ mkdir -p /root/bin
<source lang=bash>
<source lang=bash>

Revision as of 19:25, 18 October 2020

In order to let the PocketBeagle (PB) connect to the Internet a few preparations is needed.

Packets on the network is routed through a number of points. The first point a packet from the PB will run into is the Centos host. It has the IP address

In order to let the Centos route traffic from the PB to the Internet Masquerading must be enabled in the firewall. Masquerading takes packets with the source address - in this case - and changes the source address to be that of the Centos and finally routes the packet to the Internet interface - that will be your host operating system.

When packets arrives with responses from the Internet they will be sent to the Centos, which looks up in a table and from there knows that it has to change the destination address to that of the PB, i.e. Complicated, yes, but it works if you are careful in setting up the necessary things.

Preparing the Centos development host

First open the firewall interface:

Screenshot 20180223 114103.png

Next give your password.

Screenshot 20180223 114134.png

Finally you have to click a number of times on the small arrow icon the the right (marked with red circle in the figure below). The click to set the check mark as shown in the blue circle below.

Screenshot 20180223 115504.png

At the selector near the top of the window where is currently says Runtime selcet Permanent and set the check mark in the masquerade - then after reboots of the centos it will still masquerade your traffic.

Close the firewall.

Set up timezone and time

To setup a correct timezone execute this as root only once on your Pocket:

]$ sudo dpkg-reconfigure tzdata

select Europe and Copenhagen in the menu provided.

Copy over your credentials

The next step could be to copy over your credentials from development host to the PB letting you login without password. Follow the instructions over at Linux Hints page.

Preparing the PocketBeagle for connecting the Internet

The newer Debian releases provides two networks for the Bone: and Below is shown how to use the network. But, if you prefer, you can also use network.

After having set up the masquerading in the Centos host it is time to enable the Pocket on the Internet. For that the network needs to know to where it shall send packages not on the local network. Issue:

]$ sudo /sbin/route add default gw

This tells the kernel to send IP-packages, that is not part of our local network, to another node, that - hopefully - knows what to do with the package.

Isuing this command

]$ echo nameserver>>/etc/resolv.conf

tells the network system to resolve names at the given IP address.

NOTE: when using your PocketBeagle at the Aarhus University you have to find the assigned DNS server(s) because IT have blocked calls to external DNS servers. At home - and many other places - you can use, which Cloudflare provides and they promises not to track your traffic. You can also use Googles free DNS servers at or, but they may track your traffic. Alternatively if you don't want to be tracked by Google use the DNS servers given over at [1]. If prefer CLoudflares free DNS server when I'm out and about.

Unfortunately this don't stick after a reboot, So you have to issue this command every time just after booting. But wait, it can be automated. See below.

But before configuring your network to be set automatically at boot install the ntpdate utility, which is needed for synchronising the date and time to current time.


]$ apt-get update
]$ apt-get install ntpdate

Automate the network configurations

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

If /root/bin directory doesn't exists execute

]$ mkdir -p /root/bin
# 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
grep -q /etc/resolv.conf
if [ "$?" -ne "0" ]; then
        echo "nameserver" >> /etc/resolv.conf
        echo "nameserver">>/etc/resolv.conf
        echo "nameserver" >> /etc/resolv.conf
## Test for network availability
while :
        ping -c 5 -w 10
        if [ $? -eq 0 ]; then
## Now we should be ready to set the clock from the net
/usr/sbin/ntpdate -b -s -u dk.pool.ntp.org
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). Check that you get the time set to current time. If not investigate and determine why.

NOTE: Why the #!/bin/bash in top of the file? (BTW "hash-bang" or #! is often called sjabang".) See this great article on Linux Journal

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
# 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
case "$1" in
                sleep 20
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.