A poor man’s dynamic DNS on a Raspberry Pi

If you want to connect to your Digital Video Recorder (DVR) or ownCloud installation from the internet, you need to know to which IP address you need to connect (See this DVR article as well). The bad thing however is that the most of us don’t have a fixed IP address on the internet (this might change in the future with IPv6). This means your IP address can change in time. There are several payed services to solve this problem like DynDNS, DuckDNS, DtDNS, No-IP, etc. Most of the time you are the only user of the services you are hosting at home, if so than there is a cheap solution.

As described above the whole thing is, that you need to know which IP address your Raspberry Pi has. The solution is to write a script that checks your external IP address and that sends you an email in case the external IP address has changed.

Login on your Raspberry Pi with SSH:

ssh pi@your IP address
cd ~
nano ./ipaddrcheck.sh

 

Now copy and paste the following code to nano (of course you need to change username@domain.ext to your own email address):

#!/bin/bash
curl -o ~/newip ifconfig.co
cmp ~/newip ~/oldip >/dev/null || {
mv ~/newip ~/oldip
mailx -s “I – IP ${HOSTNAME} changed” username@domain.ext < ~/oldip
}

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

Make let’s make the script executable:

sudo chmod +x ./ipaddrcheck.sh

 

Let me roughly explain what the script does:
It’s a bash script that checks the external IP address by using curl ifconfig.co and writes the results to a file called newip.
After that it checks whether the IP address has changed by comparing the files newip and oldip, in case the two files are not the same it sends you an email.

 

Now we need to install the necessary packages to sent mail:

sudo apt-get install ssmtp heirloom-mailx

 

The next thing is to configure your Raspberry Pi so it’s able to send mail. Therefore you need to add the following lines, at the end of the file /etc/nail.rc :

sudo nano /etc/nail.rc

 

Now copy and paste the following code to nano (of course you need to change: smtp.domain.ext, username@domain.ext, password and email sender’s nice name to your own email settings):

# Smtp server
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.domain.ext
set smtp-auth=login
set smtp-auth-user=” username@domain.ext
set smtp-auth-password=”password”
set from=”email sender’s nice name”

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

Now we need schedule and execute the script by using crontab:

crontab -e

 

Add the following line, at the end of the file (it schedules the ipaddrcheck.sh every hour):

0 * * * * /home/pi/ipaddrcheck.sh

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

You can check the date and time stamp of the file ~/newip to see whether your script ran.

Changing the IP address in ~/oldip enables you to check whether emailing works, as it should send you an email the next time the sript runs.

 

PS. if mailing yourself doesn’t work, try editing the /etc/ssmtp/ssmtp.conf file (as it heavily depends on your mailserver configuration).

 

Suggestions for improving this article are welcome, please let me know and drop me a line .

Ubuntu upgrade resulting in a no sound situation

After working happily a couple of months with Ubuntu 10.04 I installed a new kernel with the update feature. This resulted in not having any sound or volume controls. After reading a lot on internet articles  I found the following article… Comprehensive Sound Problem Solutions Guide v0.5e I followed the following commands that brought back sound to my notebook.

Getting the ALSA drivers from a *fresh* kernel

Sometimes, sound might be configured correctly, but for some reason or another (tinkering) it stops working. One way to go back to the old setup is to reinstall Ubuntu. However, this step is actually quite unnecessary since you are reinstalling everything because of one thing.

A faster way, is to just remove the problematic packages and reinstall them cleanly.

Step – 1: Remove these packages

Code:

sudo apt-get –purge remove linux-sound-base alsa-base alsa-utils

Step – 2: Reinstall those same packages

Code:

sudo apt-get install linux-sound-base alsa-base alsa-utils

[LIST][*]

VERY IMPORTANT NOTE: Ubuntu (GNOME) users have reported that packages ‘gdm’ and ‘ubuntu-desktop’ are removed after removing the linux-sound-base packages. If this happens, then do the following

Code:

sudo apt-get install gdm ubuntu-desktop

Step – 3: Reboot

Getting Broadcom STA to work on Ubuntu Studio 13.04 or Xubuntu

As I upgraded Ubuntu Studio 12.10 to Ubuntu Studio 13.04 on my Mac Book 5.1 my wireless stopped working… After surfing the internet for a couple of days I’ve found the following solution to enable the Broadcom STA on my Mac Book 5.1.

Check whether Ubuntu sees your Broadcom STA device by running the lspci command from a terminal:

lspci | grep Network

 

After using the the lspci command you should get something like this:

03:00.0 Network controller: Broadcom Corporation BCM4322 802.11a/b/g/n Wireless LAN Controller (rev 01)

 

Next up is, installing the drivers. To install the drivers run the following command using the terminal:

sudo apt-get install firmware-b43-installer

 

The broadcom-sta-common package, blacklists the b43 driver.

To fix this you need to edit the file: /etc/modprobe.d/broadcom-sta-dkms.conf

 

You can do that by using the following command in the terminal:

sudo nano /etc/modprobe.d/broadcom-sta-dkms.conf

 

Delete or comment out with a “#” the line “blacklist b43”, my file looks like this:

# wl module from Broadcom conflicts with the following modules:
# blacklist b43
blacklist b43legacy
blacklist b44
blacklist bcma
blacklist brcm80211
blacklist brcmsmac
blacklist ssb

 

Then to force the module to load during boot by using the following command in the terminal:

sudo nano /etc/modules

 

Then add a line with “b43”, my /etc/modules file looks like this:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with “#” are ignored.
lp
rtc
b43

 

You don’t need to reboot your computer as you can load the module manually by entering the following command in the terminal:

sudo modprobe b43

 

Suggestions for improving this article are welcome, please let me know and drop me a line.

Running Google Sketchup on Wine

You can run “Sketchup the 3D modelling software for everyone from Google” in Wine on Ubuntu. In this article I’ll try to explain how to get by the error “Sketchup was unable to initialize OpenGl”.

This error is relatively easy to get by.

  • Go to your “Home folder and make sure you see all your hidden files (in Gnome File Browser go to View and select “Show Hidden Files”.
  • Go to .wine folder
  • Open the file user.reg with notepad or Gedit
  • Search for GLConfig
  • Change de “HW_OK”=dword:00000000 to “HW_OK”=dword:00000001
  • Save the changes you made in the file user.reg

Now you’re ready to start Google Sketchup on Wine

 

Suggestions for improving this article are welcome!

Please let me know and drop me a line.

How to do a ping sweep in Linux

Sometimes it can be handy to ‘see’, what is around you on a network. For instance when you’re using DHCP on a network and you want to find which addresses are already taken. Or you want to check whether specific machines are up and running… Of course there are various tools you can install or use, but there are times that you just can’t reach for the right tool(s)…

You don’t want to do a ping sweep for nothing ;-)…

Of course there is a way of ping sweeping from the command line 🙂 By simply using the ‘FOR’, ‘PIPE’ and ‘GREP’ commands in a clever way.

for i in {1..254}; do ping -c 1 -W 1 192.168.1.$i | grep ‘from’; done

Naturally you can stop the ping sweep by entering Ctrl+z

 

Suggestions for improving this article are welcome, please let me know and drop me a line.