[GUIDE] Setup Your Own Asterisk Server With Google Voice on Amazon EC2

Search This thread

errorcod3

Senior Member
Nov 2, 2012
80
23
EDIT: THIS SETUP IS FOR PEOPLE WHO WANT A RELIABLE ALTERNATE TO USING MAIN STREAM SERVICES. THIS IS YOUR OWN SERVER -- AND YOU WILL BE THE ONLY ONE USING IT AS OPPOSED TO HUNDREDS OR THOUSANDS OF OTHER USERS. I'VE BEEN USING THIS FOR SIX MONTHS WITH NO ISSUES. BEFORE THIS I WAS USING PBXES.ORG AND THE SERVICE WAS 'OK' AND I MISSED SOME CALLS. I'VE HAD ZERO ISSUES WITH THIS SETUP.

A few people have asked me for a guide on howto setup Asterisk on an Amazon EC2 micro instance for their Nexus 4. Amazon offers a free micro instance for one year (new signups). Even after your first year it's pretty cheap to keep it running. Amazon's bandwidth will be faster than setting up Asterisk on your own home server (in most cases).

Once you have the server up and running you can easily configure your favorite SIP client on your Nexus 4 to enjoy free calling with your Google Voice account. This is particularly useful for people such as myself who are on the $30 T-Mobile plan.

As a bonus, I've also included the steps to setup a PPTP VPN.

This guide assumes that you've already setup your AWS account and figured out how to set the security group. You will need to open some ports (TCP: 22, 1723, 5060. UDP: 5060, 10000-20000)

Step 1. Goto: http://uec-images.ubuntu.com/releases/10.04/release/ and pick the t1.micro instance (ebs 64 bit) for the region that you setup in AWS. Launch this instance (there is a button) and get it working with the security group that you configured. After it's launched you need to setup an Elastic IP and associate it with the instance. After that go ahead and log into your new micro instance server. Once you get to this point, then you can continue with the guide. There are TONS of resources (including youtube videos) on how to get to this point. It's not rocket science.

Step 2. Setup firewall settings for pptpd and asterisk. Lucid also has firewall settings that need to be adjusted.

Code:
#Uncomplicated Firewall
sudo ufw enable
sudo ufw allow 22/tcp
sudo ufw allow 1723/tcp
sudo ufw allow 5060/tcp
sudo ufw allow 5060/udp
sudo ufw allow 10000:20000/udp

#check status
sudo ufw status

#edit /etc/default/ufw and enable forward policy
DEFAULT_FORWARD_POLICY="ACCEPT"

#edit /etc/ufw/sysctl.conf and uncomment
net/ipv4/ip_forward=1

#edit /etc/ufw/before.rules and add this after the header comments

---<BEGIN>--- (DON'T COPY THIS LINE)
# nat Table rules
*nat
:POSTROUTING ACCEPT [0:0]

# Forward traffic through eth0.
-A POSTROUTING -o eth0 -j MASQUERADE

# don't delete the 'COMMIT' line or these nat table rules won't be processed
COMMIT
---<END>--- (DON'T COPY THIS LINE)

#disable and enable to apply changes
sudo ufw disable && sudo ufw enable

Step 3. Recompile Kernel. The default kernel is set at 100HZ timing, this will give you HORRIBLE VOIP quality. The kernel needs to be recompiled to 1000HZ timing.

Code:
# Make yourself root
sudo su

# Update source list:
aptitude update

# Upgrade everything:
aptitude upgrade 

# Install dependencies:
apt-get build-dep linux-image-$(uname -r)
apt-get build-dep linux
apt-get install fakeroot build-essential
apt-get install crash kexec-tools makedumpfile kernel-wedge
apt-get install libncurses5 libncurses5-dev
apt-get install libelf-dev asciidoc binutils-dev kernel-package
apt-get install git-core

cd /usr/src
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git 
cd ubuntu*
git checkout --track -b ec2 origin/ec2
fakeroot debian/rules clean
fakeroot debian/rules editconfigs

# Configuration window should now appear, do the following:

Select YES

# Navigate to:
Processor type and features -> Timer frequency
# Select the 1000HZ frequency 
Exit 
Exit 
Yes (Save)

#After saving and returning to prompt it may ask you to do it again for i386, select yes and repeat!

This next command will take about 7 hours to recompile the kernel. But, there is a shortcut. Amazon charges by the minute for each instance type that you use. I recommend shutting down your instance at this point and changing it to a m1 extra large instance type (this will cost you about 70 cents). This will increase your micro instance from:

613 MiB memory
Up to 2 EC2 Compute Units (for short periodic bursts)
EBS storage only
32-bit or 64-bit platform
I/O Performance: Low
EBS-Optimized Available: No
API name: t1.micro

to:

15 GiB memory
8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each)
1,690 GB instance storage
64-bit platform
I/O Performance: High
EBS-Optimized Available: 1000 Mbps
API name: m1.xlarge

The compiling time will be reduced to about 25 minutes.Once you got the instance backup with the m1.xlarge instance, continue like so:

Code:
sudo su
cd /usr/src/ubuntu*
fakeroot debian/rules binary 

#Check if your deb files were created
cd ..
ls *.deb

#install new kernel
#IF A GRUB MENU POPS UP PICK PACKAGE VERSION
sudo dpkg -i linux-*.deb

Then shutdown your system again and change it back to a micro instance. Then boot it back up.

#Check your new Kernel version
Code:
uname -r

#Check if Kernel HZ value change persisted:
cat /boot/config-`uname -r` | grep HZ

#If value 1000HZ=yes then you did it right!

Step 4. Install Asterisk 11

Code:
#become root
sudo su

# Install dependencies:
apt-get install libiksemel-dev libsqlite3-dev libssl-dev libnewt-dev libxml2-dev  

#get source
#note: dahdi needs to be installed to compile and install libpri -- we don't really need it for any other reason

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

#extract source

tar zxvf dahdi-*
tar zxvf libpri-*
tar zxvf asterisk-11*

#resolve error for compiling dahdi

ln -nsf /usr/src/linux-headers-`uname -r`/include/asm-x86 /usr/src/linux-headers-`uname -r`/include/asm

#install dahdi

cd /usr/src/dahdi*
make && make install && make config

#install libpri

cd /usr/src/libpri-1.4*
make && make install

#install asterisk
#note: once the menu pops up check and make sure you have chan_motif and xmpp (should have a * next to them)

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

Step 5. Configure Google Voice

Backup original conf files (you should still be root)

Code:
cd /etc/asterisk
cp extensions.conf extensions.conf.orig
cp motif.conf motif.conf.orig
cp sip.conf sip.conf.orig
cp xmpp.conf xmpp.conf.orig

New Config files compiled by jhax01 - GO TO POST #85 FOR MORE DETAILS. Now you will want to replace the following files with these (change USERNAME to whatever you want and make sure you google account info is correct):

#extensions.conf - Don't forget the USERNAME on the last line
Code:
[general]
autofallthrough=yes

; If an unauthenticated request some how gets through, send them to free 411.
[default]
exten => 411,1,Answer()
same => n,Dial(Motif/google/1800...@voice.google.com)

[local]
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)

[incoming-motif]
exten => s,1,NoOp()
 same => n,Set(crazygooglecid=${CALLERID(name)})
 same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
 same => n,Set(CALLERID(all)=${stripcrazysuffix})
 same => n,Dial(SIP/USERNAME,20,D(:1))

#motif.conf
Code:
[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google

#sip.conf - Pay attention to externhost, secret, and USERNAME
Code:
[general]
allow=all
allowguest=no
nat=force_rport,comedia
tcpbindaddr=0.0.0.0
tcpenable=yes

externhost=ELASTICIP
localnet=10.0.0.0/8

[USERNAME]
type=peer
secret=PASSWORDYOUGENERATE
host=dynamic
context=local
transport=udp,tcp

#xmpp.conf
Code:
[general]
[google]
type=client
serverhost=talk.google.com
username=YOUREMAIL@GMAIL.COM
secret=GMAILPASSWORD
priority=100
port=5222
usetls=yes
usesasl=yes
status=available
statusmessage="VOIP"
timeout=5

Code:
#
# Stop/Start asterisk
#
sudo /etc/init.d/asterisk stop
sudo /etc/init.d/asterisk start

If everything went at planned your Asterisk Server with Google voice should be working, you can now login with your SIP client utilizing the extension username and password that you chose in sip.conf.

BONUS STEP. PPTPD VPN

install (make sure you are still root)

Code:
apt-get install pptpd

Now take the following code and copy it into a script and execute as root:

Code:
echo "localip 10.40.1.1" >> /etc/pptpd.conf
echo "remoteip 10.40.1.20-50" >> /etc/pptpd.conf
echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd
echo "ms-dns 172.16.0.23" >> /etc/ppp/options.pptpd

pass=`openssl rand 8 -base64`
if [ "$1" != "" ]
then pass=$1
fi
echo "VPN pptpd ${pass} *" >> /etc/ppp/chap-secrets

echo -e "VPN service is installed, your VPN username is \033[1mVPN\033[0m, VPN password is \033[1m${pass}\033[1m"

Done. Just a reminder, do not upgrade the system to Ubuntu 12.04 or you will lose the recompiled Kernel. If you update the kernel you will need to recompile...
 
Last edited:

acegolfer

Senior Member
Jun 2, 2008
776
221
1. What is the advantage of this method over centos 6.3 + PIAF on EC2?

2. It seems you are using UDP transport on sip port 5060. How's the battery life when you are on 3g?
 

errorcod3

Senior Member
Nov 2, 2012
80
23
1. What is the advantage of this method over centos 6.3 + PIAF on EC2?

2. It seems you are using UDP transport on sip port 5060. How's the battery life when you are on 3g?

1. No advantage really, other than less resource are used. This is just using Asterisk 11 -- does centos/piaf combo use Asterisk 11?

2. Yes, I do use UDP because my SIP client is not running all the time. I mostly only use it for outgoing calls. The above steps could be easily adjusted for TCP use.
 

kthejoker20

Senior Member
Jun 18, 2008
835
229
Kenosha
Or you can download the obi app from play store and use that with Google voice to make WiFi calls.

Much easier to setup all you need is your login info.

Sent from my Nexus 4 using xda premium
 

acegolfer

Senior Member
Jun 2, 2008
776
221
1. No advantage really, other than less resource are used. This is just using Asterisk 11 -- does centos/piaf combo use Asterisk 11?

2. Yes, I do use UDP because my SIP client is not running all the time. I mostly only use it for outgoing calls. The above steps could be easily adjusted for TCP use.

1. I just managed to install centos + PIAF on EC2. It was a major struggle. It's using asterisk 1.8 but can add gtalk trunk with GV motif.
2. When csip uses TCP transport to connect to PIAF in EC2, I continue to experience the same hangup issue. I guess it will happen to your setup as well if you use TCP.
 

bluespire

Senior Member
Feb 26, 2009
123
17
Or you can download the obi app from play store and use that with Google voice to make WiFi calls.

Much easier to setup all you need is your login info.

Sent from my Nexus 4 using xda premium

No offense, but there is a reason this thread was made. It was spawned by the efforts of TWO other threads as an alternative solution to making VOIP work RELIABLY over 3G.

OP, you should add a blurb at the very beginning of the post that notes why this thread was made so we can curb responses like this in advance.
 

cmaxwe

Senior Member
Jun 2, 2010
105
31
Is there any advantage to doing this as opposed to getting service from a reputable VOIP provider (voip.ms, callcentric, etc) and just connecting to their servers? Surely their connection/service is going to be pretty reliable and call rates are more than reasonable (like 0.01 per minute).

These providers support G.729 so you could connect with csipsimple and have pretty good quality over 3G I think.

Are you guys doing this to avoid paying 0.01 a minute or to try to get more reliable service? I don't understand... :)
 

bluespire

Senior Member
Feb 26, 2009
123
17
Is there any advantage to doing this as opposed to getting service from a reputable VOIP provider (voip.ms, callcentric, etc) and just connecting to their servers? Surely their connection/service is going to be pretty reliable and call rates are more than reasonable (like 0.01 per minute).

These providers support G.729 so you could connect with csipsimple and have pretty good quality over 3G I think.

Are you guys doing this to avoid paying 0.01 a minute or to try to get more reliable service? I don't understand... :)

Yeah, we REALLY need that blurb about this in the OP.

We are trying to avoid any very small cost by doing this, although that was AceGolfer's original intent. The problem is that, so far, will all the previous setups using VOIP providers + GV + SIP client, there is always one thing eluding us: RELIABILITY. Really, the problem seems to stem from the fact that a single provider does not offer everything needed to make this work reliably on 3G. This stuff works great on WiFi. Even call out USUALLY work flawlessly. But INCOMING calls have been missed, traveling calls (in car) can be sketchy, and even 1 bad connection in 10 is just plain lousy.

Frankly, I can deal with some of those problems. Mine, and I'm sure many other posters', wives and business partner/clients, cannot. This is just another method to try to figure out the best and most reliable way to get VOIP on our phones.
 

acegolfer

Senior Member
Jun 2, 2008
776
221
Is there any advantage to doing this as opposed to getting service from a reputable VOIP provider (voip.ms, callcentric, etc) and just connecting to their servers? Surely their connection/service is going to be pretty reliable and call rates are more than reasonable (like 0.01 per minute).

These providers support G.729 so you could connect with csipsimple and have pretty good quality over 3G I think.

Are you guys doing this to avoid paying 0.01 a minute or to try to get more reliable service? I don't understand... :)

Here's what we (smartphone users over 3g) want: G729 (or iLBC) and TCP.

The 2 VoIP providers that you mentioned only offer UDP connection, which will kill smartphone batteries. I have heard that some people even use pbxes as the gateway for voip.ms so that they can use TCP connection.

Fortunately, there are several methods we have found that don't cost anything.
 

errorcod3

Senior Member
Nov 2, 2012
80
23
1. I just managed to install centos + PIAF on EC2. It was a major struggle. It's using asterisk 1.8 but can add gtalk trunk with GV motif.
2. When csip uses TCP transport to connect to PIAF in EC2, I continue to experience the same hangup issue. I guess it will happen to your setup as well if you use TCP.

What's the hang up issue that you are experiencing? I can switch my configuration over to TCP and see if I get the same issue.
 

errorcod3

Senior Member
Nov 2, 2012
80
23
Yeah, we REALLY need that blurb about this in the OP.

We are trying to avoid any very small cost by doing this, although that was AceGolfer's original intent. The problem is that, so far, will all the previous setups using VOIP providers + GV + SIP client, there is always one thing eluding us: RELIABILITY. Really, the problem seems to stem from the fact that a single provider does not offer everything needed to make this work reliably on 3G. This stuff works great on WiFi. Even call out USUALLY work flawlessly. But INCOMING calls have been missed, traveling calls (in car) can be sketchy, and even 1 bad connection in 10 is just plain lousy.

Frankly, I can deal with some of those problems. Mine, and I'm sure many other posters', wives and business partner/clients, cannot. This is just another method to try to figure out the best and most reliable way to get VOIP on our phones.

I have been using this setup for about 6 months. It's incredibly reliable. I'm the only one using this server as opposed to more main stream options where hundreds or thousands of people are using the service. Plus, I can use it for other things such as a VPN server when I need it.
 

errorcod3

Senior Member
Nov 2, 2012
80
23
ADD TCP SUPPORT

On your security group settings for the Amazo EC2 open port 5060/tcp.

login and execute:

Code:
sudo ufw allow 5060/tcp


Edit sip.conf and add the following under the [general] section:

Code:
tcpbindaddr = 0.0.0.0
tcpenable = yes

Under your [USERNAME] in sip.conf add the following:

Code:
transport=udp,tcp

restart asterisk

ADDED TO OP.
 
Last edited:

osi13

Senior Member
Jun 25, 2010
373
127
It looks like you're only using G711u/a, and GSM for codecs. Have you tried installing G729? Or allowing G722?
 

acegolfer

Senior Member
Jun 2, 2008
776
221
What's the hang up issue that you are experiencing? I can switch my configuration over to TCP and see if I get the same issue.

When Csipsimple is registered remotely (obviously is the case for EC2) using TCP, it takes 30 seconds to hangup after pressing the "end" call button. The voice gets transmitted during these 30 seconds.

OTOH, the call hangs up normally, if CSS uses UDP or I use a different client which costs to use G729.
 

errorcod3

Senior Member
Nov 2, 2012
80
23
It looks like you're only using G711u/a, and GSM for codecs. Have you tried installing G729? Or allowing G722?

No, I haven't tried it. Asterisk 11 supports G722. If anyone is interested in using it just add an allow=g722 to the sip.conf file under [general].

Does Google Voice support G729?
 
Last edited:

errorcod3

Senior Member
Nov 2, 2012
80
23
When Csipsimple is registered remotely (obviously is the case for EC2) using TCP, it takes 30 seconds to hangup after pressing the "end" call button. The voice gets transmitted during these 30 seconds.

OTOH, the call hangs up normally, if CSS uses UDP or I use a different client which costs to use G729.

I just changed my configuration to TCP and I could not reproduce your problem. My calls terminate normally..
 

Top Liked Posts

  • There are no posts matching your filters.
  • 19
    EDIT: THIS SETUP IS FOR PEOPLE WHO WANT A RELIABLE ALTERNATE TO USING MAIN STREAM SERVICES. THIS IS YOUR OWN SERVER -- AND YOU WILL BE THE ONLY ONE USING IT AS OPPOSED TO HUNDREDS OR THOUSANDS OF OTHER USERS. I'VE BEEN USING THIS FOR SIX MONTHS WITH NO ISSUES. BEFORE THIS I WAS USING PBXES.ORG AND THE SERVICE WAS 'OK' AND I MISSED SOME CALLS. I'VE HAD ZERO ISSUES WITH THIS SETUP.

    A few people have asked me for a guide on howto setup Asterisk on an Amazon EC2 micro instance for their Nexus 4. Amazon offers a free micro instance for one year (new signups). Even after your first year it's pretty cheap to keep it running. Amazon's bandwidth will be faster than setting up Asterisk on your own home server (in most cases).

    Once you have the server up and running you can easily configure your favorite SIP client on your Nexus 4 to enjoy free calling with your Google Voice account. This is particularly useful for people such as myself who are on the $30 T-Mobile plan.

    As a bonus, I've also included the steps to setup a PPTP VPN.

    This guide assumes that you've already setup your AWS account and figured out how to set the security group. You will need to open some ports (TCP: 22, 1723, 5060. UDP: 5060, 10000-20000)

    Step 1. Goto: http://uec-images.ubuntu.com/releases/10.04/release/ and pick the t1.micro instance (ebs 64 bit) for the region that you setup in AWS. Launch this instance (there is a button) and get it working with the security group that you configured. After it's launched you need to setup an Elastic IP and associate it with the instance. After that go ahead and log into your new micro instance server. Once you get to this point, then you can continue with the guide. There are TONS of resources (including youtube videos) on how to get to this point. It's not rocket science.

    Step 2. Setup firewall settings for pptpd and asterisk. Lucid also has firewall settings that need to be adjusted.

    Code:
    #Uncomplicated Firewall
    sudo ufw enable
    sudo ufw allow 22/tcp
    sudo ufw allow 1723/tcp
    sudo ufw allow 5060/tcp
    sudo ufw allow 5060/udp
    sudo ufw allow 10000:20000/udp
    
    #check status
    sudo ufw status
    
    #edit /etc/default/ufw and enable forward policy
    DEFAULT_FORWARD_POLICY="ACCEPT"
    
    #edit /etc/ufw/sysctl.conf and uncomment
    net/ipv4/ip_forward=1
    
    #edit /etc/ufw/before.rules and add this after the header comments
    
    ---<BEGIN>--- (DON'T COPY THIS LINE)
    # nat Table rules
    *nat
    :POSTROUTING ACCEPT [0:0]
    
    # Forward traffic through eth0.
    -A POSTROUTING -o eth0 -j MASQUERADE
    
    # don't delete the 'COMMIT' line or these nat table rules won't be processed
    COMMIT
    ---<END>--- (DON'T COPY THIS LINE)
    
    #disable and enable to apply changes
    sudo ufw disable && sudo ufw enable

    Step 3. Recompile Kernel. The default kernel is set at 100HZ timing, this will give you HORRIBLE VOIP quality. The kernel needs to be recompiled to 1000HZ timing.

    Code:
    # Make yourself root
    sudo su
    
    # Update source list:
    aptitude update
    
    # Upgrade everything:
    aptitude upgrade 
    
    # Install dependencies:
    apt-get build-dep linux-image-$(uname -r)
    apt-get build-dep linux
    apt-get install fakeroot build-essential
    apt-get install crash kexec-tools makedumpfile kernel-wedge
    apt-get install libncurses5 libncurses5-dev
    apt-get install libelf-dev asciidoc binutils-dev kernel-package
    apt-get install git-core
    
    cd /usr/src
    git clone git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git 
    cd ubuntu*
    git checkout --track -b ec2 origin/ec2
    fakeroot debian/rules clean
    fakeroot debian/rules editconfigs
    
    # Configuration window should now appear, do the following:
    
    Select YES
    
    # Navigate to:
    Processor type and features -> Timer frequency
    # Select the 1000HZ frequency 
    Exit 
    Exit 
    Yes (Save)
    
    #After saving and returning to prompt it may ask you to do it again for i386, select yes and repeat!

    This next command will take about 7 hours to recompile the kernel. But, there is a shortcut. Amazon charges by the minute for each instance type that you use. I recommend shutting down your instance at this point and changing it to a m1 extra large instance type (this will cost you about 70 cents). This will increase your micro instance from:

    613 MiB memory
    Up to 2 EC2 Compute Units (for short periodic bursts)
    EBS storage only
    32-bit or 64-bit platform
    I/O Performance: Low
    EBS-Optimized Available: No
    API name: t1.micro

    to:

    15 GiB memory
    8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each)
    1,690 GB instance storage
    64-bit platform
    I/O Performance: High
    EBS-Optimized Available: 1000 Mbps
    API name: m1.xlarge

    The compiling time will be reduced to about 25 minutes.Once you got the instance backup with the m1.xlarge instance, continue like so:

    Code:
    sudo su
    cd /usr/src/ubuntu*
    fakeroot debian/rules binary 
    
    #Check if your deb files were created
    cd ..
    ls *.deb
    
    #install new kernel
    #IF A GRUB MENU POPS UP PICK PACKAGE VERSION
    sudo dpkg -i linux-*.deb

    Then shutdown your system again and change it back to a micro instance. Then boot it back up.

    #Check your new Kernel version
    Code:
    uname -r
    
    #Check if Kernel HZ value change persisted:
    cat /boot/config-`uname -r` | grep HZ
    
    #If value 1000HZ=yes then you did it right!

    Step 4. Install Asterisk 11

    Code:
    #become root
    sudo su
    
    # Install dependencies:
    apt-get install libiksemel-dev libsqlite3-dev libssl-dev libnewt-dev libxml2-dev  
    
    #get source
    #note: dahdi needs to be installed to compile and install libpri -- we don't really need it for any other reason
    
    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
    
    #extract source
    
    tar zxvf dahdi-*
    tar zxvf libpri-*
    tar zxvf asterisk-11*
    
    #resolve error for compiling dahdi
    
    ln -nsf /usr/src/linux-headers-`uname -r`/include/asm-x86 /usr/src/linux-headers-`uname -r`/include/asm
    
    #install dahdi
    
    cd /usr/src/dahdi*
    make && make install && make config
    
    #install libpri
    
    cd /usr/src/libpri-1.4*
    make && make install
    
    #install asterisk
    #note: once the menu pops up check and make sure you have chan_motif and xmpp (should have a * next to them)
    
    cd /usr/src/asterisk*
    ./configure && make menuselect && make && make install && make config && make samples

    Step 5. Configure Google Voice

    Backup original conf files (you should still be root)

    Code:
    cd /etc/asterisk
    cp extensions.conf extensions.conf.orig
    cp motif.conf motif.conf.orig
    cp sip.conf sip.conf.orig
    cp xmpp.conf xmpp.conf.orig

    New Config files compiled by jhax01 - GO TO POST #85 FOR MORE DETAILS. Now you will want to replace the following files with these (change USERNAME to whatever you want and make sure you google account info is correct):

    #extensions.conf - Don't forget the USERNAME on the last line
    Code:
    [general]
    autofallthrough=yes
    
    ; If an unauthenticated request some how gets through, send them to free 411.
    [default]
    exten => 411,1,Answer()
    same => n,Dial(Motif/google/1800...@voice.google.com)
    
    [local]
    exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    
    [incoming-motif]
    exten => s,1,NoOp()
     same => n,Set(crazygooglecid=${CALLERID(name)})
     same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
     same => n,Set(CALLERID(all)=${stripcrazysuffix})
     same => n,Dial(SIP/USERNAME,20,D(:1))

    #motif.conf
    Code:
    [google]
    context=incoming-motif
    disallow=all
    allow=ulaw
    connection=google

    #sip.conf - Pay attention to externhost, secret, and USERNAME
    Code:
    [general]
    allow=all
    allowguest=no
    nat=force_rport,comedia
    tcpbindaddr=0.0.0.0
    tcpenable=yes
    
    externhost=ELASTICIP
    localnet=10.0.0.0/8
    
    [USERNAME]
    type=peer
    secret=PASSWORDYOUGENERATE
    host=dynamic
    context=local
    transport=udp,tcp

    #xmpp.conf
    Code:
    [general]
    [google]
    type=client
    serverhost=talk.google.com
    username=YOUREMAIL@GMAIL.COM
    secret=GMAILPASSWORD
    priority=100
    port=5222
    usetls=yes
    usesasl=yes
    status=available
    statusmessage="VOIP"
    timeout=5

    Code:
    #
    # Stop/Start asterisk
    #
    sudo /etc/init.d/asterisk stop
    sudo /etc/init.d/asterisk start

    If everything went at planned your Asterisk Server with Google voice should be working, you can now login with your SIP client utilizing the extension username and password that you chose in sip.conf.

    BONUS STEP. PPTPD VPN

    install (make sure you are still root)

    Code:
    apt-get install pptpd

    Now take the following code and copy it into a script and execute as root:

    Code:
    echo "localip 10.40.1.1" >> /etc/pptpd.conf
    echo "remoteip 10.40.1.20-50" >> /etc/pptpd.conf
    echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
    echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd
    echo "ms-dns 172.16.0.23" >> /etc/ppp/options.pptpd
    
    pass=`openssl rand 8 -base64`
    if [ "$1" != "" ]
    then pass=$1
    fi
    echo "VPN pptpd ${pass} *" >> /etc/ppp/chap-secrets
    
    echo -e "VPN service is installed, your VPN username is \033[1mVPN\033[0m, VPN password is \033[1m${pass}\033[1m"

    Done. Just a reminder, do not upgrade the system to Ubuntu 12.04 or you will lose the recompiled Kernel. If you update the kernel you will need to recompile...
    4
    Ok, so now I know more about Asterisk then originally planned, but that 's not a bad thing...lol. I'll share a few of my findings to hopefully help others who give this a try.

    I did a lot of chasing to figure out what was wrong with my inbound calls, but as it turns out the solution was very simple. The short version is that my inbound call issues were tied directly to the Gtalk server. Setting Asterisk's priority to "1" made sure it was dead last when it came to initiating any inbound connections whatsoever. And, in fact, any inbound calls would terminate at the Gtalk server and never even hit Asterisk's horizon. It all worked initially for me because I wasn't logged in anywhere at first, but when I booted up the N4, it auto logged into Gtalk. So, if you're using a dedicated email/voice acct, you may not run into this issue, but for me, the fix was as simple as setting the priority in XMPP.conf to 100. Just FYI - A side effect of this is most likely to be that now all inbound connections terminate at Asterisk and Gtalk doesn't get a chance at them.

    As a cautionary item, setting sip.conf to allow guests is a bit dangerous unless you define their limitations or are on a local network behind a hardware firewall. The current one is written in this guide will allow *anyone* to utilize your PBX and by extension, your google voice account. If your GV account is set to auto refill with $$....well, you get the idea... Additionally, for this particular application, most of the parameters specified in the [general] section of sip.conf aren't needed. Just specify the no guest thing and any protocols you would like to use.

    There is also some danger to use the [default] section in extensions.conf if you are trying to operate privately as Asterisk will look there to dial whenever it receives an undefined request. This again exposes you to potential mischief.

    One other tip is on your outbound calls you can define multiple formats so you don't have to change the way you normally dial, in addition to local calls, like so:


    exten => _1XXXXXXXXXX,1,Dial(Motif/USERNAME/${EXTEN}@voice.google.com,,r)

    ** this covers dial requests formatted as 1-555-444-1234

    exten => _XXXXXXXXXX,1,Dial(Motif/jhaxgvsip/${EXTEN}@voice.google.com,,r)

    ** this covers dial requests formatted as 555-444-1234

    etc, etc....

    Thanks again, errorcod3! I never would have even attempted this if it weren't for your guide! :D
    2
    This worked for adding call recording. All calls are recorded and saved to: /var/spool/asterisk/monitor

    replace extensions.conf with this (Don't forget to change USERNAME on last line):

    Nice, nice, nice....

    Haven't been able to get TLS working over SIP, but I did add an IAX channel which allows md5 and rsa authentication out of the box. Apparently IAX coupled with G729 has much lower latency and bandwidth requirements than a SIP connection. Call quality has been very good for me, but I haven't had a truly dodgy connection to know how well it works. The only drawback is that it is UDP, so there is potentially the battery issue if your keep alive intervals are short. Set up couldn't be simpler, all that needs to be done is to mod iax.conf like so:

    Code:
    iax.conf
    
    [general]
    autokill=yes
    allow=all
    jitterbuffer=yes
    
    [USERNAME]
    type=friend
    auth=md5,rsa
    secret=YOURPASSWORD
    host=dynamic
    context=local

    USERNAME and YOURPASSWORD obviously need to be different than the ones used in sip.conf. context=local points the outbound calls @ the google voice extensions. Now the only other thing to do is add inbound support in extensions.conf:

    Code:
    extensions.conf
    
     same => n,Dial(IAX2/IAXUSERNAME,20,D(:1))

    Add the above line just underneath the last line under [incoming-motif] in extensions.conf.

    You will also need to open port 4569/udp in your security group as well as ufw.

    After modding, you may need to reboot the EC2 server to get the IAX channel functioning properly. Simply restarting Asterisk didn't work for me.

    I'm using Zoiper as an IAX client. Now on an inbound call, Asterisk will ring both the SIP and IAX client concurrently. Obviously you don't want to be logged in to both on the same phone at the same time as you will get a double ring.

    I also have multiple Google Voice numbers via the same client functioning. Inbound calls from any number of GV#s ring the phone just fine. Selection of which number to use for the outbound calls is made through some case management of the exten commands. It seems that Asterisk is willing to ignore the * and + sign...so one, both, or a combo is used to select the outbound phone line. I'll post up what I have tomorrow. The only thing that is lacking is parsing the inbound call to show which phone line is being used. I'm sure someone around here will be able you figure that out quite easily.
    2
    In the battle to get this working for myself, I happened to learn a few things proving that you can, in fact, teach an old dog new tricks...lol. I'm going to add my *.conf here with a bit of explanation that may help others understand what's going on with each of the files. I certainly didn't understand at first, but as I researched my issues a little deeper, the light bulb slowly started to come on.

    I'll start with "motif.conf"...the sole purpose here is to let Asterisk know that we are intending to utilize Google as a conduit for communication and that calls will originate or terminate in the context defined in motif.conf. We also make sure that Asterisk knows to only use the ulaw protocol as that is the only way Google Voice knows how to communicate.

    Code:
    motif.conf
    
    [google]
    context=incoming-motif
    disallow=all
    allow=ulaw
    connection=google

    Next is xmpp.conf - This is where we define the resource that is available to Asterisk to accomplish the connection to the google account. As errorcod3 stated - make sure you put in the correct gmail info.... Also note that we are generically defining a connection type below and coupling this with the context of "incoming-motif" above gives us a mechanism for making and receiving calls. Essentially, the "how" that Asterisk will apply to make or receive a call. Additionally, make sure you set the priority high if you are using a google account that make be logged into Gtalk somewhere else. If it is set to 1 under those circumstances, the call will never make it to Asterisk.



    Code:
    xmpp.conf
    
    [general]
    [google]
    type=client
    serverhost=talk.google.com
    username=YOUREMAIL@GMAIL.COM
    secret=GMAILPASSWORD
    priority=100
    port=5222
    usetls=yes
    usesasl=yes
    status=available
    statusmessage="VOIP"
    timeout=5


    Now we can define our soft phone or SIP client. This is our connection into Asterisk just as motif/xmpp are Asterisk's connection to google chat.


    Code:
    sip.conf
    
    [general]
    allow=all
    allowguest=no
    nat=force_rport,comedia
    tcpbindaddr=0.0.0.0
    tcpenable=yes
    
    externhost=EXTERNALIP
    localnet=IFCONFIG/SUBNETMASK
    
    [USERNAME]
    type=peer
    secret=PASSWORDYOUGENERATE
    host=dynamic
    context=local
    transport=udp,tcp

    Here's where I differ from errorcod3's methodology a bit. In the general section, I'm telling Asterisk that it's ok to accept any compression protocols for the SIP => Asterisk portion of the connection with "allow=all". The only drawback to this is that if the compression type is not supported or compiled with Asterisk, then it will attempt to pass through the protocol rather than transcode it. Gtalk itself supports several types, but Google Voice, on the other hand, only supports ulaw. So if it passes through something unsupported there will be no audio. The upside is that it allows you to switch protocols on the fly easily. *allowguest=no* - this one is important if your server is in the open (i.e. - EC2). Leaving it out, or setting the parameter to *yes* will allow anyone to use your PBX to dial out unconditionally as long as they know the IP. The next lines allow TCP as a protocol and set nat to yes, essentially. Everything after USERNAME defines your actual soft phone connection and lets Asterisk know that when you initiate a call, it should use the context *local* to route it.


    Lastly, we have extensions.conf. This is where we set our dial plan for Asterisk or the "conditions" that tell it to do what and when.

    extensions.conf

    Code:
    [general]
    autofallthrough=yes
    
    ; If an unauthenticated request some how gets through, send them to free 411.
    [default]
    exten => 411,1,Answer()
    same => n,Dial(Motif/google/1800...@voice.google.com)
    
    [local]
    exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    
    [incoming-motif]
    exten => s,1,NoOp()
     same => n,Set(crazygooglecid=${CALLERID(name)})
     same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
     same => n,Set(CALLERID(all)=${stripcrazysuffix})
     same => n,Dial(SIP/USERNAME,20,D(:1))

    Ok, line by line, this is what we are doing here.

    autofallthrough - we set this to yes so that if Asterisk runs out of things to do with an active connection or has problems, it will send a busy signal, or hang up, or whatever. Otherwise, it will just sit there will an open connection and wait for another extension to be dialed.

    [default] - This is what Asterisk will do if it receives a dial request from an un-authenticated guest. We already have it set to not allow guests, but just in case, if something gets through somehow, we are going to send them to free 411. It will effectively ignore any dial requests that are not made from the SIP client we define in sip.conf.

    [local] - think of this context as our outbound calls or the connection from your soft phone to the world. When you dial out, sip.conf points your request at the context of *local*, then under local Asterisk matches a formatting case to the appropriate extension. Then in the case of the above, Asterisk places the call through the "Motif" technology via the "google" account we defined in xmpp.conf.

    [incoming-motif] - This context handles our inbound calls from google voice by first stripping out everything but the phone number on the inbound transmission. Then, in the last line, it dials the soft phone defined in sip.conf to complete the connection.


    The above conf files will provide an audio only connection. I'm also currently working on adding TLS authentication for the SIP client instead of sending the user name and password in the clear and if the OP is in agreement, I will add the directions. (your authentication into google voice is already sent encrypted) Hope I didn't overstep my bounds... Just trying to help clarify what is going on for folks like myself who didn't have a clue at first. :D

    ---------- Post added at 10:49 PM ---------- Previous post was at 10:44 PM ----------

    Some people claim that simonics is more reliable than asterisk GV module and chan_motif. Haven't verified it myself though.

    In fact, I use both in my PIAF. If I call a 10 digit number, GV module places the call. If I call a 1+ 10 digit number, then GVGW (w/ a different GV number). No difference in call quality (tested with 2 N4's side by side).

    Oh, I see... As near as I can tell, reliability is more a function of your SIP client and it's ability to keep connected with the server. I haven't had any issues...so far anyway. :)

    Call quality-wise, I added g729 to my setup and am pretty happy with it so far.

    ---------- Post added at 10:55 PM ---------- Previous post was at 10:49 PM ----------

    In addition to what acegolfer said:
    As far as I know, it simplifies the process of using GV with VoIP devices. It also has Caller ID name lookup for incoming calls through your GV number, but I believe it's possible to add that functionality to Asterisk. If anything, I'm just enjoying the learning process involved with messing around with different Asterisk configurations B)

    Yep, you definitely can.... A couple other interesting things I came across are sending blocked calls to a privacy manager that requires them to input their number before it will complete the call & blacklists, etc.... Asterisk has a ridiculous amount of options....
    1
    No, I haven't tried it. Asterisk 11 supports G722. If anyone is interested in using it just add an allow=g722 to the sip.conf file under [general].

    Does Google Voice support G729?

    gtalk trunk only supports PCMU (g711 ulaw), which is used at PSTN. asterisk will transcode PCMU to other codecs such as G729.