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.
Close the firewall.
Set up tiezone and time
To setup a correct timezone execute this as root only once on your Pocket:
]$ 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
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
]$ echo nameserver 10.83.252.10>>/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 Googles free DNS servers at 18.104.22.168 or 22.214.171.124. Alternatively if you don't want to be tracked by Google use the DNS servers given over at CensurfriDNS.
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
#!/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 126.96.36.199 /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 188.8.131.52" >> /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:
$] 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 ### 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.