Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,332 Members 52,606 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
errorcod3
Old
(Last edited by errorcod3; 5th February 2013 at 04:04 PM.)
#1  
errorcod3's Avatar
Member - OP
Thanks Meter 22
Posts: 80
Join Date: Nov 2012
Default [GUIDE] Setup Your Own Asterisk Server With Google Voice on Amazon EC2

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:
Select 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:
Select 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:
Select 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:
Select 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:
Select 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:
Select 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:
Select 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:
Select Code
[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google
#sip.conf - Pay attention to externhost, secret, and USERNAME
Code:
Select 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:
Select 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:
Select 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:
Select Code
apt-get install pptpd
Now take the following code and copy it into a script and execute as root:

Code:
Select 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...
The Following 18 Users Say Thank You to errorcod3 For This Useful Post: [ Click to Expand ]
 
CrazyPeter
Old
#2  
Senior Member
Thanks Meter 418
Posts: 1,084
Join Date: Sep 2010
Eh? Understood none of that. What even is Asterisk?
 
errorcod3
Old
#3  
errorcod3's Avatar
Member - OP
Thanks Meter 22
Posts: 80
Join Date: Nov 2012
Quote:
Originally Posted by CrazyPeter View Post
Eh? Understood none of that. What even is Asterisk?
https://www.asterisk.org/
 
acegolfer
Old
#4  
Senior Member
Thanks Meter 209
Posts: 699
Join Date: Jun 2008
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
Old
#5  
errorcod3's Avatar
Member - OP
Thanks Meter 22
Posts: 80
Join Date: Nov 2012
Quote:
Originally Posted by acegolfer View Post
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
Old
#6  
Senior Member
Thanks Meter 143
Posts: 637
Join Date: Jun 2008
Location: Kenosha
Default Re: [GUIDE] Setup Your Own Asterisk Server With Google Voice on Amazon EC2

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
Check out my Nexus 4 tool, Image Extractor and Image backup/restore to PC CLICK HERE


 
acegolfer
Old
#7  
Senior Member
Thanks Meter 209
Posts: 699
Join Date: Jun 2008
Quote:
Originally Posted by errorcod3 View Post
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
Old
#8  
Senior Member
Thanks Meter 15
Posts: 109
Join Date: Feb 2009
Quote:
Originally Posted by kthejoker20 View Post
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
Old
#9  
Member
Thanks Meter 23
Posts: 80
Join Date: Jun 2010
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
Old
#10  
Senior Member
Thanks Meter 15
Posts: 109
Join Date: Feb 2009
Quote:
Originally Posted by cmaxwe View Post
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.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes