PB:Get an Internet connection
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 192.168.6.1.
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 - 192.168.6.2 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. 192.168.6.2. 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:
Next give your password.
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.
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.
So after this operation you'll have a check mark in both the runtime settings as well as in the permanent settings.
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: 192.168.7.0/30 and 192.168.6.0/30. Below is shown how to use the 192.168.6.0/30 network. But, if you prefer, you can also use 192.168.7.0/30 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 192.168.6.1
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
]$ sudo echo nameserver 10.83.252.10>>/etc/resolv.conf ]$ sudo echo nameserver 18.104.22.168 >> /etc/resolv.conf
tells the network system to resolve names at the given IP address.
Test that the nameservices works by entering
]$ host a.dk
expect something like
a.dk has address 22.214.171.124
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 126.96.36.199, which Cloudflare provides and they promises not to track your traffic. You can also use Googles free DNS servers at 188.8.131.52 or 184.108.40.206, but they may track your traffic. Alternatively if you don't want to be tracked by Google use the DNS servers given over at . 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
Username@beaglebone ]$ sudo su - root@beaglebone ]$ mkdir -p /root/bin
Now mark this text below. Start vi
root@beaglebone ]$ vi internetOverUSB
press i to get into insert mode. Press shift ins to paste the text in. Hit Esc key to bring vi into command mode. Save an quit by entering :wq.
#!/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.6.1 grep -q 220.127.116.11 /etc/resolv.conf if [ "$?" -ne "0" ]; then echo "nameserver 10.83.16.53" >> /etc/resolv.conf echo "nameserver 10.83.252.10">>/etc/resolv.conf echo "nameserver 18.104.22.168" >> /etc/resolv.conf fi ## Test for network availability while : do ping -c 5 -w 10 192.168.6.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:
root@beaglebone $] chmod u+x internetOverUSB
Test the script by issuing:
root@beaglebone ]$ ./internetOverUSB
Check that you get the time set to current time. If not investigate and determine why. Also check that you can resolve hostnames by entering
root@beaglebone ]$ host a.dk
expect something like: a.dk has address 22.214.171.124
If you run into problems here try to figure out what causes the problem.
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 ### 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
$] 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.