Asterisk on Azure IaaS with Google Voice!

Google Voice Loves Azure and Asterisk!

Asterisk can work pretty well on Microsoft Windows Azure even with Google Voice, you don’t even need to be a Linux genius; so here are the simple steps to get it working!

Create the virtual machine

Create an Azure Virtual Machine

If you don’t have Virtual Machine (IaaS) you will need to sign up for the preview. It’s pretty quick, so go do it already. For just connecting one SIP phone to one Google Voice account an Extra Small ($10/month or free with an MSDN subscription) will be plenty big enough, so choose Ubuntu Server 12 as the image and Extra Small as the size. Key in your password and pick a location close to you. The DNS name is important, because you will use it to connect via SSH and from your SIP device.

Now Azure will build a virtual machine for you, so let’s learn how to connect to it. I assume you are awesome, and hence are using Google Chrome so we can jump straight to the Chrome Web Store and pick up a free copy of Secure Shell which will let you access the command line of your virtual machine form any operating system that supports Chrome. Got it? Good. Click it.

Secure Shell App Icon

Setup a new connection with the user name as azureuser@<your DNS here>.cloudapp.net similar to this:

Secure Shell Settings

If you can’t connect then it’s likely because you haven’t started your virtual machine (I’m not sure why Microsoft doesn’t do this for you but whatever,) just click into your virtual machine on Azure and click the start button.

Upon successful connection you will be prompted for your password, which is the same password you entered when creating the virtual machine. Simple!

Now let’s check for updates by entering the following command line:

sudo apt-get update

What does this do? Sudo is a command that temporarily give super user permissions to the current user. The best way to understand it is with the xkcd comic:

Sudo give you super-powers! But use it responsibly. Think of apt-get as a way of getting things your computer doesn’t have. Linux distributions are famous for coming with not enough stuff or conversely too much stuff, since this is a server we start with not enough stuff and just add what we need. As for update, well I’d let you use your imagination but it just updates the packages from the internet so we always get the latest and greatest stuff.

Okay, so let’s install Asterisk 11 which if you build it correctly has built in support for google voice! Huzzah! So unfortunately we will need to build from source since Ubuntu hasn’t seen fit to put Asterisk 11 prebuilt binaries into the apt-get (Aptitude) repository for easy getting. No Problem! “Building from sources,” sounds scary but is down-right brain-dead easy, I mean a monkey could get this right and you are way smarter than a monkey, right? RIght?!? Okay, let’s do it. First we need a “build environment,” which is fancy-talk for the programs that we need to build Asterisk from its sources. It’s easy to get so copy from below (windows: control + c // mac: command + c) and paste into your Secure Shell window (windows: shift + control + v // mac: command + shift + v).

sudo apt-get install build-essential wget libssl-dev libncurses5-dev libnewt-dev  libxml2-dev inux-headers-$(uname -r) libsqlite3-dev libiksemel-dev libssl-dev

This part will take a little time as Ubuntu goes out and gets all the software it needs to make Asterisk. So get yourself a lovely beverage or something. When it’s done we are going to need to have super-powers for real, so we are going to go into superuser mode by running this command:

sudo su -

Next we will need to download the Asterisk source code:

cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz

And extract it:

tar zxf dahdi-linux-complete*
tar zxf libpri*
tar zxf asterisk*

Now we will build and install the DAHDI module (which is required by Asterisk):

cd /usr/src/dahdi-linux-complete*
make && make install && make config

As for PRI, we need to do a little extra work, but it too will build just fine:

cd ../libpri*
curl https://issues.asterisk.org/jira/secure/attachment/44869/fix_unused_write.patch > fix.patch
patch -i fix.patch
make && make install

Now we can finally build Asterisk!

cd /usr/src/asterisk*
./configure && make menuselect && make && make install && make config && make samples

This will flash some scrolling text and then display a menu which you can just for F12 or press TAB until you get to Save and Exit. Asterisk will continue building and installing and whatnot and you should get a prompt at the end of it all. Congratulations, you are almost done! There’s just a couple configuration files and settings we will need to make before the whole thing is working.

Note: You will need to edit some of these files I’m giving you to fill in your real Google Voice credentials, and then paste them into the console.

First we will create the sip.conf file:

cat > /etc/asterisk/sip.conf

Now you will see a new blank line and a blinking cursor, paste the following text into here:

[general]
allowguest=no
allowoverlap=no
udpbindaddr=0.0.0.0
srvlookup=yes
nat=yes
externip=[Get this from your Azure dashboard "PUBLIC VIRTUAL IP ADDRESS (VIP)"]
localnet=[Get this form your Azure dashboard "INTERNAL IP ADDRESS"]/255.255.254.0
bindaddr=0.0.0.0
qualify=yes

[gvgw](!)
type=peer
host=dynamic
context=local
disallow=all
allow=ulaw

[sipphone](gvgw)
secret=[Put in the password you want here]

And press Control + c to exit and save the file.

cat > /etc/asterisk/xmpp.conf
[general]
[google]
type=client
serverhost=talk.google.com
username=[Your gmail address]
secret=[Your gmail password]
priority=1
port=5222
usetls=yes
usesasl=yes
status=dnd
statusmessage="Phone Gateway!"
timeout=5
cat > /etc/asterisk/motif.conf
[default](!)
disallow=all
allow=ulaw
allow=h264
transport=google-v1

[google](default)
transport=google
connection=google
context=incoming-google
cat > /etc/asterisk/extensions.conf
[default]
exten => 411,1,Answer()
same => n,Dial(Motif/google/${EXTEN}@voice.google.com)

[incoming-google]
exten => s,1,Set(CALLERID(name)=${CALLERID(num)})
same => n,Dial(SIP/sipphone,20,D(:1))

[local]
include => default
exten => _NXXNXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _NXXXXXX,1,Dial(Motif/google/[Your 3 digit area code here]${EXTEN}@voice.google.com,,r)

Now that’s done we can start Asterisk!

/etc/init.d/dahdi start
/etc/init.d/asterisk start
asterisk -rvvv

Now you will be in an Asterisk shell and it will show you everything that’s going on under the hood. Probably a lot of errors and Google will be sending you a freaked out email that some application is trying to access your account! Yes, that’s your new Asterisk box, and let it do its thing. One you have let Google know not to freak out you’ll be close to done, you just need to go to your Azure dashboard and click on Endpoints and add the following endpoints:

UDP 10000
UDP 10001
UDP 10002
UDP 10003
UDP 10004
UDP 10005
UDP 10006
UDP 5060
TCP 5269

I’m sorry but as of the time of this writing there’s no easier way to add these endpoints without using PowerShell and that’s a whole other conversation. This way is tiresome but easy.

Yay! Time to use the system!

If you call your Google Voice number at this point you should see Asterisk spitting out all kinds of things are generally freaking out because there’s nowhere to send the call to. In order to fix this, all you have to do is download a SIP client like Telephone for Mac OS X or X-Lite for Windows or use a little device that hooks up to your internet and a telephone. Just configure it to point at your DNS name (xxx.cloudapp.net) and the extension name (in my scripts it’s sipphone) and the password (which is something you should have put in my script). Once it’s connected you should be able to make and receive calls on your Google Voice account!

Mighy Guy / Rock Lee

 

Now enjoy your system and go add compiling Linux applications and administering Azure IaaS to your resume!

One thought on “Asterisk on Azure IaaS with Google Voice!”

  1. ^_^ i like reading about this. It was written well and in such a way that I didn’t feel overwhelmed by the information you provided. Nice Job, keep up the cool work!

Leave a Reply