Posts Tagged ‘ubuntu’

SMS Gateway with Kanneland Huawei 3G Modem on Ubuntu

08 Dec

Source: Setting Up an SMS Gateway with Ubuntu 8.04, Kannel and Huawei E220 GSM Modem

I’ve used the link above as a guide to how I did my installation. The one I did was way easier though, as I didn’t have to compile the source anymore. It might have been the version of Kannel that we used that is different. The above guide used 1.4.1 whereas I used 1.4.3 that came with Ubuntu’s packages.

Anyway, the model I used for the GSM Modem is a Huawei E156C HSDPA USB Stick, not a E220 GSM Modem. I used the same identifier as the E220 though, and so far no problems. Should work just fine.

First off, let’s install Kannel.

sudo apt-get install kannel

Next, configure Kannel by editing the configuration file found in /etc/kannel/kannel.conf. My configuration file is shown below

group = core
admin-port = 13000
admin-password = ourkannelpassword
admin-deny-ip = "*.*.*.*"
admin-allow-ip = ""
wapbox-port = 13002
smsbox-port = 13003
wdp-interface-name = "*"
log-file = "/var/log/kannel/bearerbox.log"
box-deny-ip = "*.*.*.*"
box-allow-ip = ""
unified-prefix = "+"

group = wapbox
bearerbox-host = localhost
log-file = "/var/log/kannel/wapbox.log"

group = modems
id = huawei_e220_00
name = "Huawei E220"
detect-string = "huawei"
init-string = "AT+CNMI=2,1,2,2,0"
message-storage = sm
speed = 460800

group = smsc
smsc = at
smsc-id = smsc-smart-bro
port = 10000
modemtype = huawei_e220_00
device = /dev/ttyUSB1
sms-center = "+XXXXXXXXXXXX"
connect-allow-ip = ""
log-file = "/var/log/kannel/smsc.log"

group = smsbox
bearerbox-host = localhost
smsbox-id = smsbox-smart-bro
log-file = "/var/log/kannel/smsbox.log"

group = smsbox-route
smsbox-id = smsbox-smart-bro
smsc-id = smsc-smart-bro

group = sms-service
keyword = default
text = "No service defined"
catch-all = true

There are a bazillion ways to configure Kannel, and since I’m new at this, I just used the barebones minimum for receiving and processing SMS messages. The important part here is how to configure the modem, and the smsc (Defined by the group setting) to work together.

Lucky for us that Ubuntu ships with drivers for this modem. Once you connect the modem on a USB port, you can check it with the following command:


You should see something like this. As you can see, even if I used a E156C model, it detects it as the E220 HSDPA Modem.

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

It should also attach a tty onto it. In my case, it attaches to both /dev/ttyUSB0, and /dev/ttyUSB1.

To make sure where that is attached to, run:

udevadm info -q all -n /dev/ttyUSB0
udevadm info -q all -n /dev/ttyUSB1

You should be able to see on which device it is connected to.

Going back to Kannel configuration, we need to find out how to configure the modem in kannel.conf. Basically, it’s just knowing the right parameters to set. For the modem group, the important thing is the init-string. I’m not an expert on it, so I just copied it from the Huawei forums. Basically, it uses AT commands (you can try playing with it in minicom or in HyperTerminal if you are on Windows).

Next is to configure the smsc group. Here, we define the modemtype to use the modem that we just configured. This modem type is the id assigned to the modem. At the same time, we need to tell the smsc to connect to which device, in my case, it’s /dev/ttyUSB1. Check out the source link from above why we used ttyUSB1 instead of ttyUSB0. It has to do with the main loop and event handling where there will be no more delay because ttyUSB1 will fire an event whenever an SMS is received (or something like that).

Once that is done, I setup smsbox-route just to be sure that smsc forwards everything to the smsbox defined, as well as future proofing it if I add more smsbox, and smsc configurations in the future. This would avoid more confusion later.

Next, the tricky part. We restart the kannel service. Now, the kannel service will be starting 2 daemons by default. The bearerbox daemon, as wel as the wapbox daemon. But it only shows ‘Starting WAP gateway’ as the message. I checked my processes, and then there it was, only the bearerbox and wapbox service. No smsbox. If you look into the init script, it will check for a $START_WAPBOX, $START_SMSBOX variable to start the daemons. I didn’t realize this until I dug deeper 2 hours since I started. Apparently, you need to edit /etc/default/kannel to set these environment variables. By default, you will see this:


So to start the smsbox, you just edit that file, uncomment the 2nd line, and then restart the kannel service.

Once you start the service, the SMSC log will report a PERMISSION DENIED, and will not be able to start the service. This is because if you look at the permissions of /dev/ttyUSB1, it is owned by root:dialout. This is easy to fix. We just need to add the user kannel into the dialout group by running the following command:

sudo usermod -G dialout kannel

Then restart the kannel service:

sudo /etc/init.d/kannel restart

That’s it!


Posted in HowTo, Mobile


Autorun Screen Sessions on an SSH Session

06 May

Source: Automatic ‘screen’ on remote logins

It annoys me whenever an SSH session I have to a server drops, and I can’t reconnect to the session, especially when there’s a long running tasks that I need to know the status of.

So anyway, the solution to this one is a project called GNU Screen. To summarize, it creates a virtual terminal session for you that you can actually resume on if ever your connection (or whatever) was terminated.

The problem with it is that you have to manually invoke the screen command when you successfully login, like so:

screen -D -RR

To run it on every SSH session, you can a script it to your bashrc profile. Either with your own bashrc located in ~/.bashrc or a global profile in /etc/bash.bashrc for all users. I normally put it for all users.

The script to add is found below, and is taken from

# Auto-screen invocation. see:
# if we're coming from a remote SSH connection, in an interactive session
# then automatically put us into a screen(1) session.   Only try once
# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping
# if screen fails for some reason.
if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ]
  [ -d $HOME/lib/screen-logs ] || mkdir -p $HOME/lib/screen-logs
  sleep 1
  screen -RR && exit 0
  # normally, execution of this rc script ends here...
  echo "Screen failed! continuing with normal bash startup"
# [end of auto-screen snippet]
No Comments

Posted in HowTo


Installing Oracle 10g on Ubuntu 9.10 (Karmic Koala) Server 64-bit

27 Apr

Source: Installing Oracle 10g On Ubuntu Karmic 64 Bit or OtherwiseInstalling Oracle 10g On Ubuntu Karmic 64 Bit Or Otherwise (Part 2)

So apparently I needed to install Oracle 10g to Ubuntu, and ran through a lot of hassles. I found a guide that’s well written but had some trouble with 64-bit server, and am writing for this for others who will encounter some trouble as well.

I’m breaking this down the following sections:

  1. Installing Required Libraries
  2. Setting Up Users and Groups
  3. Setting Kernel Parameters
  4. Emulating SUSE and Red Hat
  5. Setting Up the Oracle Environment
  6. Installing Oracle
  7. Creating the Listener
  8. Creating a Database
  9. Creating Startup/Shutdown Scripts

Installing Required Libraries

Since Ubuntu is not an officially supported OS, we need to emulate those that are, and since Oracle mixes 32-bit and 64-bit libraries, we need to install i386, and even ia32 libraries. Run the following:

sudo apt-get install libaio1 rpm gcc-multilib libc6-dev-i386 libc6-dev-i386 libc6-i386 ia32-libs

In addition, doesn’t come with LIBSTDC++5, so you have to install manually installing the package. Run the following:

wget ""
ar vx libstdc++5_3.3.6-17ubuntu1_amd64.deb
tar zxvf data.tar.gz
file usr/lib/
sudo install usr/lib/ /usr/lib32/
cd /usr/lib32
sudo ln -s
cd /usr/lib
sudo ln -s /usr/lib32/

Setting Up Users and Groups

We need to create the group oinstall, dba, and nobody, and create a user named oracle. Run the following:

sudo groupadd oinstall
sudo groupadd dba
sudo groupadd nobody
sudo useradd -m oracle -g oinstall -G dba -s /bin/bash

And don’t forget to change the password.

sudo passwd oracle

Take note of the oinstall group ID as you will need this in setting the Kernel Parameters later. Do this by running the code below:

cat /etc/group | grep oinstall

The ID should be in the format 10XX. If it’s a newly installed system, it should be 1002.

Setting Kernel Parameters

We need to override the kernel parameters by running the following:

sudo vi /etc/sysctl.conf

And add the settings below at the bottom of the file. Take note that the [oinstall_group_id] should be replaced with what you got in the steps above (1002).

vm.hugetlb_shm_group = [oinstall_group_id]
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000

Reload the parameters by running the following:

sudo /sbin/sysctl -p

We also need to edit limits of the system. Edit the limits.conf file by running:

sudo vi /etc/security/limits.conf

Add add the settings below to the bottom of the file.

* soft nproc 2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536

Emulating SUSE and Red Hat

We emulate SUSE by creating symbolic links of the following:

sudo ln -s /usr/bin/awk /bin/awk
sudo ln -s /usr/bin/rpm /bin/rpm
sudo ln -s /lib/ /lib/
sudo ln -s /usr/bin/basename /bin/basename

We emulate Red Hat by creating the redhat-release file to trick the Oracle Installer that we are using Red Hat. =) Edit the file:

sudo vi /etc/redhat-release

And add the following:

Red Hat Enterprise Linux AS release 3 (Taroon)

Setting Up the Oracle Environment

I normally install my oracle database inside /opt so from hereon, you have to take note that /opt/oracle/10g will be the oracle home, and /opt/oracle will be the oracle base. The SID I will be using here will be orcl. Run the following:

sudo mkdir -p /opt/oracle/10g
sudo chown -R oracle:oinstall /opt/oracle
sudo chmod -R 775 /opt/oracle

Update environment profile by editing the global profile.

sudo vi /etc/profile

And add the following settings at the bottom.

export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/10g
export ORACLE_SID=orcl

Installing Oracle

Proceed with installation. My install directory is in /home/installers Unpack the downloaded oracle installer:

gunzip 10201_database_linux_x86_64.cpio.gz
cpio -id < 10201_database_linux_x86_64.cpio
sudo chown -R oracle:oinstall .

Normally, Ubuntu Server doesn’t have X server installed, so you will have problems running the installer as it actuallly has GUI. The easiest way to install this is to access a desktop with X server, and create a connection with SSH forwarding.

ssh -X oracle@oracle-server

From there, fire up the installer:

cd /home/installers/database

The GUI should come out on your client machine. Once the installer is up, uncheck the “Create Starter Database” option, and keep clicking on Next to accept the defaults.

If you encounter some error about the “collector” you can just ignore this as Ubuntu is not supported.

After the installation, the installer will ask you to run two scripts as root. Run them as is.

Oracle is Installed! X_X

Creating the Listener

We create the listener by running the Network Configuration Assistant (needs X server). As with the installer, we need to have X forwarding enabled. The command should be in the oracle path, if not, there might have been a problem with setting up the oracle environment. Run the following as oracle user:


Just use the defaults and create the listener.

Creating the Database

We create a database by running the Database Configuration Assistant (needs X). We also need X forwarding enabled here. Run the assistant with the following:


Create the database as you please. Although you have to take note of the Database Name/SID, and it should match the ORACLE_SID environment variable you set on the /etc/profile file.

Creating Startup/Shutdown Scripts

First, we need to edit the /etc/oratab file.

sudo vi /etc/oratab

My oratab file contains the following:


Change the last character, N, to Y.

Next, we edit dbstart as oracle user. Run the following:

vi $ORACLE_HOME/bin/dbstart

Look for the following line:


Just change that to your ORACLE_HOME (/opt/oracle/10g) and save the file.

Create a startup script found in /etc/init.d/ named dbora. The following script is taken here. Take note of the ORACLE_HOME and ORACLE_SID variables.

# /etc/init.d/dbora
# Startup script for Oracle databases

export ORACLE_HOME=/opt/oracle/10g
export ORACLE_SID=orcl

case "$1" in
echo -n "Starting Oracle: "
su oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/oracle

su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
echo "OK"
echo -n "Shutdown Oracle: "
su oracle -c $ORACLE_HOME/bin/dbshut
rm -f /var/lock/oracle
echo "OK"
echo "Usage: 'basename $0' start|stop"
exit 1
exit 0

Modify the file so it is executable

sudo chmod 775 /etc/init.d/dbora

Register it in Ubuntu’s startup script by running the following:

sudo update-rc.d dbora defaults 99

Everything should be working as is. Try to access Enterprise Manager by accessing port 1158 (default) through HTTP.


Installing PostgreSQL 8.4, PostGIS 1.4.1, and pgRouting 1.0.3 on Ubuntu 9.10 (Karmic Koala)

01 Feb

Go to the bathroom before we start this one! hehe

I’m breaking this into the following 3 sections:

  1. Installing PostgreSQL 8.4
  2. Installing PostGIS 1.4.1
  3. Installing pgRouting 1.0.3

Installing PostgreSQL 8.4

Get a working copy of PostgreSQL running. At the time of this writing, Ubuntu has deprecated PostgreSQL 8.3, and has 8.4 as stable. So that’s what aptitude will install here.

sudo apt-get install postgresql

Normally, you wouldn’t have access to the database right now. You need to use the postgres user to set up. I’d recommend not changing the password of the postgres user. Just create a PostgreSQL super user.

sudo su -l postgres
createuser -E -P -s dbsuperuser

Now, try to login to the database with the super user you just created.

psql -U dbsuperuser -W -h postgres

You should come out with the following prompt:


Installing PostGIS 1.4.1

We’re compiling PostGIS, so we gotta get compilers. Normally you’d have them, unless you made a minimal install. I usually just get the build-essential package to get it over with.

sudo apt-get install build-essential
sudo apt-get install libgeos-dev
sudo apt-get install proj
sudo apt-get install postgresql-server-dev-8.4

You need the last one to be able to compile PostGIS. Had a lot of trouble without it, so I just added it. =)

Get the latest version of PostGIS here. At this time, PostGIS is at 1.4.1.

tar zxvf postgis-1.4.1.tar.gz
cd postgis-1.4.1
sudo make install

Everything should be compiled. Now we need to create the PostGIS database template. I normally have the naming scheme of template_XXX, so I’m naming my database as template_postgis.

For the next few statements, you can either switch to the postgres user, so you don’t have to enter the password everytime. I normally use the super user I create to do this.

createdb -U dbsuperuser -h -W -E UNICODE template_postgis
createlang -U dbsuperuser -h -W -d template_postgis plpgsql
psql -U dbsuperuser -h -W template_postgis &lt; /usr/share/postgresql/8.4/contrib/postgis.sql
psql -U dbsuperuser -h -W template_postgis &lt; /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql

Check your PostGIS installation with the following command:

psql -U dbsuperuser -h -W -c "SELECT postgis_lib_version();" template_postgis

Should give you the version of your PostGIS.

Installing pgRouting 1.0.3

You can follow the official guide here.

Now it gets complicated. Stable version 1.0.3 of pgRouting as of the moment isn’t compatible to compile with 8.4. You have to edit some code… not really. Just add a few include headers in the C files. =)

Let’s begin by installing dependencies. First up, libboost… this is a huge library.

sudo apt-get install libboost-graph-dev
sudo apt-get install cmake

Next, gaul. Check out the latest ones here. Right now, mine’s 0.1850-0.

tar -zxvf gaul-devel-0.1850-0.tar.gz
cd gaul-devel-0.1850-0
./configure --disable-slang
sudo make install
sudo ldconfig

Get pgRouting here. Now, I don’t use DD so I skipped installing CGAL and DD.

tar -zxvf pgRouting-1.03.tgz
cd pgrouting/
cmake -DWITH_TSP=on

At this point, if cmake spits out an error like this:

core/src/dijkstra.c: In function ‘fetch_edge_columns’:
core/src/dijkstra.c:98: error: ‘INT4OID’ undeclared (first use in this function)
core/src/dijkstra.c:98: error: (Each undeclared identifier is reported only once
core/src/dijkstra.c:98: error: for each function it appears in.)
core/src/dijkstra.c:100: error: ‘FLOAT8OID’ undeclared (first use in this function)

There’s an issue with PostgreSQL 8.4. v1.0.3 still doesn’t support 8.4 at the moment (pgRouting Ticket #160), so I have to edit the following files (Hat tip to thge on this one):


Just add the line:

#include "catalog/pg_type.h"

That’ll make pgRouting see PostgreSQL 8.4 data types.

cmake -DWITH_TSP=on
sudo make install

pgRouting should now be installed in /usr/share/postlbs. As I said before, I like my database naming schemes, so I’m creating another template for pgRouting called template_pgrouting. Create the database with template_postgis as your base template.

createdb -U dbsuperuser -h -W -E UNICODE -T template_postgis template_routing
psql -U dbsuperuser -h -W template_routing < /usr/share/postlbs/routing_core.sql
psql -U dbsuperuser -h -W template_routing < /usr/share/postlbs/routing_core_wrappers.sql
psql -U dbsuperuser -h -W template_routing < /usr/share/postlbs/routing_topology.sql
psql -U dbsuperuser -h -W template_routing < /usr/share/postlbs/routing_tsp.sql
psql -U dbsuperuser -h -W template_routing < /usr/share/postlbs/routing_tsp_wrappers.sql

We’re done!! Grab a coke and go pee!

Update: Fixed package name from build-essentials to build-essential; Added postgres to the psql command to connect to database; Thanks Thera


Setting Up an Ubuntu 9.10 (Karmic Koala) Linode VPS

21 Jan

So I was shopping for a VPS over the past week and decided that Linode would be a good choice. My deciding factor? Check out the benchmarks here by Eivind Uggedal (Thanks btw).

So anyway, here’s a summary:

  1. Getting Started with Linode
  2. Setup SSH
  3. Setup Firewall

Getting Started with Linode

Now, basically, you’ll want to follow the Getting Started with Linode guide… for me, just setup your default settings, and connect to the server through SSH.

Once in, you’ll want to secure your system. We’ll do an upgrade.

apt-get update
apt-get upgrade

Now, create your user, change the password, and add it as a sudoer.

adduser -m john
passwd john
# visudo uses nano or vi as the editor depending on your environment, normally it's nano on the first try
# In case you aren't familiar with these, just use your favorite text editor and edit /etc/sudoers

Look for the line:

root    ALL=(ALL) ALL

And add the following line below it:

john    ALL=(ALL) ALL

Oh and btw, change john to whatever username you wish.

Setup SSH

This is the most important. Brute force attackers will hit the port 22 first and run common usernames and passwords against. If they detect that port 22 is not open, they’ll just give up on your IP, and move on to the next. So this is very, VERY important. I make mine listen to… just kidding. I’m not telling you of course. Anyway, to change the port, edit /etc/ssh/sshd_config (Use whatever text editor you are comfortable with, mine’s VI):

sudo vi /etc/ssh/sshd_config

Edit the following configurations:

Port 22
PermitRootLogin yes

Change listening port to whatever port you might want to listen to (E.G. 22123), and disallow root login (change it to no). Save your file, and restart your SSH service by running:

sudo /etc/init.d/ssh restart

You just made your server 10-fold more secure.

Setup Firewall

So Ubuntu recommends ufw (Uncomplicated Firewall). This isn’t uncomplicated at all if you are used to iptables as you have to relearn the commands. No fear, it’s pretty simple. First up, let’s get it working:

sudo apt-get install ufw
# Next line is depending on the SSH port that you allowed, very, Very, VERY important! =)
sudo ufw allow 22123
# Next 2 lines is if you want HTTP/HTTPS, which you most probably will
sudo ufw allow 80
sudo ufw allow 443

That’s it. If you want to delete the rule again, just run:

sudo ufw delete deny 80

And it’ll remove block the HTTP service.