How-To Guide for Google Voice with Freepbx 14 & asterisk gvsip, Ubuntu 18.04

This no longer works

However this overall guide may be useful for some as a guide for setting up Freepbx for Ubuntu. Alex Wiesen Head of Engineering, Google Voice has said the method of using GVsip is against their terms of service. The method described here will flat out not work(it will not register, trying to implement this for google voice will waste your time). I won’t be trying to further circumvent the issue now that we know where google stands regarding this. I still use google hangouts on my android phone, best of luck to everyone, was exciting and fun to use while it lasted. I am now considering other SIP providers for my home phone service. (we finally moved to an alternative paid voip service)

to read more about it start here:

click here to see the original guide

How to Guide for Google Voice calls with Freepbx 14 & asterisk gvsip, Ubuntu 18.04
If you follow this tutorial start to finish, google voice calls should work without issue.

gvsip info:
Nafs Gvsip: GitHub - naf419/asterisk at gvsip
wiki known issues: Home · naf419/asterisk Wiki · GitHub

Last Tested August 16, 2018

Any questions pertaining to this guide, please ask them here.
The discussion link posted above is for those that have gvsip installed and working and wish to contribute logs and help with debugging any issues with gvsip as they crop up.

Install Ubuntu 18.04 server (any ubuntu 18.04 will do, I just prefer server or minimal)

Anywhere that I use 7775551234, replace with your 10-digit google voice number.
When prompted to enter your ITU-T telephone code, search “country dialing codes” (US is 1)

ffmpeg+lame optional, required for m4a+mp3, HTML5 format converters.
mailutils optional, required for sending email with voicemail attachment, or Module Update emails.
fail2ban optional, recommended for security.
mongodb optional, used for some XMPP features, have had no trouble without it.

Install dependencies:

sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt dist-upgrade -y

sudo apt install -y git curl apt-transport-https net-tools mpg123 sox apache2 \
libapache2-mod-php5.6 libapache2-mod-security2 libmysqlclient-dev mysql-client \
mysql-server php-pear php5.6 php5.6-cgi php5.6-cli php5.6-curl php5.6-fpm \
php5.6-gd php5.6-mbstring php5.6-mysql php5.6-odbc php5.6-xml \
unixodbc ffmpeg lame fail2ban mailutils mongodb

Install nodejs (optional, but required for UCP module, which I find useful so I recommend installing):

curl -sL | sudo -E bash -
sudo apt install -y nodejs

Prep system for asterisk & Freepbx:

sudo a2enmod rewrite
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php5.6-fpm
sudo sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
sudo sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sudo sed -i 's/^memory_limit =.*/memory_limit = 256M/' /etc/php/5.6/apache2/php.ini
sudo sed -i 's/^upload_ma.*/upload_max_filesize = 120M/' /etc/php/5.6/apache2/php.ini
sudo rm -rf /var/www/html

Clone Naf’s gvsip branch:

cd /usr/src
sudo git clone --branch gvsip
cd asterisk
sudo sed -i 's/MAINLINE_BRANCH=.*/MAINLINE_BRANCH=15/' build_tools/make_version
sudo contrib/scripts/install_prereq install
sudo contrib/scripts/
sudo reboot

Next we need to build asterisk:

cd /usr/src/asterisk
sudo ./configure
sudo make menuselect.makeopts

sudo menuselect/menuselect --enable format_mp3 --enable app_macro \
--enable CORE-SOUNDS-EN-WAV --enable CORE-SOUNDS-EN-ULAW menuselect.makeopts

sudo make
sudo make install
sudo make config
sudo ldconfig
sudo update-rc.d -f asterisk remove

Set initial config and permissions:

sudo touch /etc/asterisk/{modules,ari,statsd}.conf
sudo cp configs/samples/smdi.conf.sample /etc/asterisk/smdi.conf

sudo useradd -m asterisk
sudo chown asterisk. /var/run/asterisk
sudo chown -R asterisk. /var/{lib,log,spool}/asterisk
sudo chown -R asterisk. /etc/asterisk /usr/lib/asterisk /var/www
Setup Mysql ODBC driver (Optional, only used for CDR/CEL, to view click here)
cat << EOF | sudo tee --append /etc/mysql/conf.d/mysqld.cnf

sudo service mysql restart

cat << EOF | sudo tee --append /etc/odbc.ini
Description=MySQL connection to asteriskcdrdb database

Download & Install the driver:

tar -xzf mysql-connector-odbc-5.3.11-linux-ubuntu18.04-x86-64bit.tar.gz
rm -f mysql-connector-odbc-5.3.11-linux-ubuntu18.04-x86-64bit.tar.gz
cd mysql-connector-odbc-5.3.11-linux-ubuntu18.04-x86-64bit
sudo cp bin/* /usr/bin/
sudo cp lib/* /usr/lib/x86_64-linux-gnu/odbc/
sudo myodbc-installer -a -d -n "MySQL" -t "Driver=/usr/lib/x86_64-linux-gnu/odbc/"
sudo ldconfig
sudo odbcinst -i -d -f /etc/odbcinst.ini
sudo odbcinst -i -s -l -f /etc/odbc.ini
sudo odbcinst -q -d

Install Latest Freepbx:

sudo su
cd /usr/src
tar vxfz freepbx-14.0-latest.tgz
rm -f freepbx-14.0-latest.tgz
cd freepbx
./start_asterisk start
./install -n

Now setup a Systemd service:

cat << EOF | sudo tee /lib/systemd/system/freepbx.service
Description=FreePBX VoIP Server

ExecStart=/usr/sbin/fwconsole start -q
ExecStop=/usr/sbin/fwconsole stop -q


Next enable and start the service:

sudo systemctl enable freepbx
sudo systemctl start freepbx
sudo systemctl status freepbx
If you prefer or required init.d instead of systemd click here

sudo nano /etc/init.d/freepbx

#! /bin/bash

# Provides:          freepbx
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: freepbx service
# Description:       Run Freepbx service


start() {
        echo -n "Starting FreePBX Components: "
        $FWCONSOLE start
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
        return $RETVAL

stop() {
        echo -n "Shutting down FreePBX Components: "
        $FWCONSOLE stop
        [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
        return $RETVAL

status() {
                if pgrep -x asterisk > /dev/null; then
                echo -e "Asterisk is Running\r\n"
                echo -e "Asterisk appears to be NOT running\r\n"
                if pgrep -x mysqld > /dev/null; then
                echo -e "MySQL is Running\r\n"
                echo -e "MySQL appears to be NOT running\r\n"
                if pgrep -x httpd > /dev/null; then
                echo -e "Apache is Running\r\n"
                echo -e "Apache appears to be NOT running\r\n"

case "$1" in
        $FWCONSOLE chown
        $FWCONSOLE reload
        $FWCONSOLE stop
        $FWCONSOLE start
        [ -f /var/lock/subsys/freepbx ] && restart || :
        echo "Usage: freepbx {start|stop|status|reload|restart"
        exit 1
exit $?

ctrl + x to save and exit

sudo chmod 755 /etc/init.d/freepbx
sudo update-rc.d freepbx defaults
sudo systemctl enable freepbx
sudo reboot

Upon reboot your asterisk/freepbx/node should start automatically.

sudo systemctl status freepbx

Now open a browser and enter the machines http://IP.ADDRESS.GOES.HERE/index.php to finish setup. You will be asked to create an admin account and choose localization settings.
Once the dashboard loads you will see error “No Conference Room App”, Ignore it.
The first save+apply will make that error go away, next visit to Dashboard it will be gone.

Admin -> Module Admin
 Check Online, look for modules that have updates,
  click into them and select download and upgrade,
  I recommend installing "CID Superfecta" and "Phonebook" modules.
  If using "User Control Panel", install now so its ready during extension creation.
   UCP requirements, "user management", "process management", "certificate manager"
 then click process at the top or bottom of page.

 Other Very useful modules to install (optional):
  Blacklist, IVR, Ring Groups

Settings -> Asterisk SIP Settings
 "General SIP Settings"-Tab
   NAT Settings, External Address, click detect network settings
   Delete TURN server username & pass
   Stun Server Address:   (Optional, usually)

 "Chan PJSIP Settings"-Tab
   tls - - All - YES

Applications -> Extensions
 Add New Chan_SIP Extension
  Optionally on "Voicemail Tab" voicemail enabled, set password/email, attachment yes

Connectivity -> Trunks
 Add Trunk -> Add Custom Trunk
   Trunk Name: gvtrunk1
   Outbound CallerID 7775551234

  "custom Settings"-Tab
   Custom Dial String: PJSIP/[email protected]

Connectivity -> Outbound Routes
 Add Outbound Route
  "Route Settings"-Tab
   Route Name: gvout1
   Route CID: (blank)
   override extension No
   route password: (blank)
   Route type: (leave default)
   music on hold?: (leave default)
   route position: (leave default)
   trunk sequence for matched routes: gvtrunk1
   optional destination on congestion: Normal Congestion

  "Dial Patterns"-Tab

Connectivity -> Inbound Routes
 Add Inbound Route
   Description: gvin1
   DID Number: 7775551234
   Set Destination: 701

   Enable Superfecta Lookup: YES
Submit & Apply

Next you need to configure your softphone, ATA, or sip phone to use your extension.
with softphone CSipSimple you create a “Basic” type account, toward the bottom, lt will prompt for four fields

Account name: 701
User: 701
Password: passwordhere

Below is a picture showing my PAP2T ATA, the config will be different in each SIP phone, I have highlighted the important parts.

Edit pjsip_custom_post.conf to make use of the new gvsip:
There are 6 lines <change me> that need changed, make sure you get them all, look carefully
Actually 7 lines including contact_user=7775551234 (set this to your 10 digit google voice number)

sudo nano /etc/asterisk/pjsip_custom_post.conf


client_uri=sip:<your choice for device identifier>
contact_additional_params=obn=<name to appear on GV settings page>

refresh_token=<your oauth refresh token>
oauth_clientid=<your oauth client id>
oauth_secret=<your oauth client secret>
username=<your choice for device identifier>



ctrl+x to save and exit

here is how to get your OAuth 2.0 Client ID, Client Secret, and refresh token for gvsip: How-To Guide for Creating Oauth credentials for Google Voice gvsip

For <your choice for device identifier>, make it unique such as gv7775551234
Also None of the fields that need edited should include quotes in your pjsip_custom.conf file
If you use the above guide for getting your refresh token from google, you will notice they present it with it in quotes, but when you enter the token into the file it should be without the quotes

sudo reboot
sudo asterisk -rvvv

Both the asterisk CLI and log files can help with troubleshooting if things are not working properly.
You can view the asterisk log files from Reports → Asterisk Log Files
Start by looking for the ERROR[] lines that are in RED.
The asterisk CLI is useful to watch as your troubleshooting something such as trying to place or receive a call.

Now try placing a call from one of your extensions, If it does not work, try 1-2 more reboots, if it still does not work consult your Asterisk CLI and Asterisk Log files for clues.

After you have placed some calls both incoming and outgoing. You should start securing and locking down your installation. This is a VERY broad topic, and there is no way I can cover it all here, but I will touch on a couple basics.

First goto Settings → Asterisk SIP Settings and turn off guest and anonymous use of your Server.
This is to prevent random people from registering and placing calls with your phone number.

Next, simply installing fail2ban does not setup the jail for asterisk, only for sshd, so lets make a jail for asterisk that uses the default log configuration, this can be adjusted to point to different log files if you have made adjustments to your log file settings.

If not you will ban your own phone, and then wonder why it is not registering or working.
If you suspect you banned yourself, you can check for your IP: sudo fail2ban-client status asterisk

cat << EOF | sudo tee --append /etc/fail2ban/jail.local
enabled = true
port = 5060,5061,5160,5161,4569
action = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
         %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
         %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s"]
logpath = /var/log/asterisk/full
maxretry = 2
bantime = 172800
findtime = 1200

Next load the new settings and see the status before and after:

sudo fail2ban-client status
sudo fail2ban-client reload
sudo fail2ban-client status
sudo fail2ban-client status asterisk

There are LOTS of guides that cover security, search google for securing ubuntu server, securing freepbx, securing asterisk, etc and you should find plenty of info.

I recommend backing up your system prior to making changes if you have a working system
That way you can always restore from a backup.

Install Support for the Opus codec for HD Voice (optional, to view click here)
cd /usr/src
sudo wget
sudo tar -xvzf codec_opus-16.0_current-x86_64.tar.gz
cd codec_opus-16.0_1.3.0-x86_64
sudo cp /usr/lib/asterisk/modules/
sudo cp codec_opus_config-en_US.xml /var/lib/asterisk/documentation/thirdparty
sudo reboot

sudo asterisk -rvvvv
core show translation
module show like opus
(The above two commands should show opus is loaded)

Settings -> Asterisk SIP Settings
 "General SIP Settings"-Tab
   Audio Codecs Section at bottom, enable Opus, and set codec priorities.

Opus may only work with intel CPUs, if Opus breaks your asterisk then remove it:

sudo rm /usr/lib/asterisk/modules/
sudo rm /var/lib/asterisk/documentation/thirdparty/codec_opus_config-en_US.xml
sudo reboot

To Later update the system with Naf’s latest changes:

sudo apt update
sudo apt dist-upgrade

cd /usr/src/asterisk
sudo make clean
sudo make distclean
sudo git checkout HEAD^ build_tools/make_version
sudo git pull
sudo sed -i 's/MAINLINE_BRANCH=.*/MAINLINE_BRANCH=15/' build_tools/make_version
sudo contrib/scripts/install_prereq install
sudo ./configure
sudo make menuselect.makeopts

sudo menuselect/menuselect --enable format_mp3 --enable app_macro \
--enable CORE-SOUNDS-EN-WAV --enable CORE-SOUNDS-EN-ULAW menuselect.makeopts

sudo make
sudo make install
sudo reboot

Cool stuff here.

1 Like


Does this work with the freepbx iso installation too?

I decided to try this yesterday. I installed a FreePBX Distro ISO and then built Asterisk from source in /usr/local/src. I then installed overtop of the Asterisk already in place. It works, but there’s a bit of clean-up to do. Of course this also screws up the update system which is a huge feature of the distro. Not worth it, in my opinion. If you’re going to build Asterisk from scratch, then do the manual/open-source install of FreePBX also.

1 Like

Bill, does that mean that there’s hope your service will come back to life? :pray:

1 Like

No. This is about helping the Asterisk/FreePBX community with a DIY solution so that a gateway service is not necessary.

1 Like

Much of what is being done here in _custom.conf files can be done in the GUI for a nicer integration.

Settings -> Asterisk SIP Settings -> STUN Server Address:

Set up a custom Trunk first, and make the Dial string = “PJSIP/[email protected]

Then set up Outbound Routes as usual, using 1 + NXXNXXXXXX and 1NXXNXXXXXX to represent NANP numbers and select your custom trunk as the target.

Omit these from the custom file and instead just enable the UDP and TLS transports in the Asterisk SIP Settings -> Chan_PJSIP settings screen.

The rest should go in the pjsip_custom_post.conf file because the GUI doesn’t have all the options that were added.

In the type=registration section, add contact_user=GVNUM replacing GVNUM with your number, and then you can use Inbound Routes to route the incoming call.


Thank you so much billsimon! I really appreciate that and am going to try these changes today!

After trying it out, I will update the guide to include all of these changes.

Awesome Info! Exactly what I was hoping to do actually, but you obviously have a really good understanding of how it all works.

Which field should I add the stun address to? or is it both?

how viable is it to spin up a second asterisk install just to be a gvoice gateway, and setup a sip trunk between the main freepbx and the ‘gateway’? until freepbx implements this internally, anyway

A very simple asterisk basic install (with NAF’s patches) providing a pass through trunk to a full-on FreePBX would need surprisingly routing on the NAF , just a choice of chan_sip or chan_pjsip between the FBX and the NAF

Whichever one results in it putting the stunaddr into the rtp_additional.conf file :slight_smile:

I think it’s the Media Transport Settings

By the way, I’m not certain this is required. I tested without it and it works fine, but my server has a public IP (no NAT).

Did you find that you needed to install any new packages for openssl, libssl, libssl-dev or anything like that? I ask because I have seen where some people apparently have had issues due to having an old version of SSL-related packages, so I thought maybe you might have installed them and forgot to mention them, unless Ubuntu 18.04 already has them.

When you get the asterisk source files, there a shell script included:-


It conveniently looks for the software A) that is necessary and B) that the ‘addons’ like to have. It is OS independent and will in this case, have suggested and then by request have the appropriate package manager install all the above.

If you regularly “roll-your-own” you will have long ago have realized that it might well save hours later in the ./configure/make/make install/make config/test_if_you_got_what_you_want cycle.

Edit : After reviewing the install process, you found the mp3 script in that directory but you REALLY don’t want to do “make samples” thing on a working FreePBX :wink:

( the other scripts in that directory are also worth looking at :slight_smile: )

1 Like

@dicko I am assuming that means on a fresh install, meaning the first time setting it up after install ubuntu, it would be ok to do the “make samples” then.

But when you build again the latest changes, you should NOT be running that command? I assume it would wipe out some of the changes you made if you did.

Thanks, and if I am assuming this correctly. I will make note of it in the opening post.

It would probably be ‘ok’ but it would be a waste of time if two lines later you install FreePBX, from that point onwards, modifying anything that is not a “custom” or “override” file will not be “a good thing”, Just delete that ‘unnecessary’ from your process and you will be fine.

I’ve followed the asterisk rebuild process presented for IncrediblePBX from page 26267 of the nerdvittles site (can’t post the link).

Everything compiles without error, but I don’t have a working system. If anybody can explain why I can’t place an outgoing call, I’d appreciated it:

== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
> 0xb6324220 – Strict RTP learning after remote address set to:
– Executing [6085------@from-internal:1] Set(“SIP/1024-00000003”, “CALLERID(dnid)=6085------”) in new stack
– Executing [6085------@from-internal:2] Set(“SIP/1024-00000003”, “CALLERID(dnid)=16085------”) in new stack
– Executing [[email protected]:3] Goto(“SIP/1024-00000003”, “16085------,1”) in new stack
– Goto (from-internal,16085------,1)
– Executing [16085------@from-internal:1] Set(“SIP/1024-00000003”, “CHANNEL(accountcode)=Google Voice”) in new stack
– Executing [1608------@from-internal:2] Dial(“SIP/1024-00000003”, “PJSIP/16085------@gvsip,r”) in new stack
[2018-07-04 18:53:17] ERROR[3286]: chan_pjsip.c:2215 request: Unable to create PJSIP channel - endpoint ‘gvsip’ was not found
[2018-07-04 18:53:17] WARNING[3285][C-00000002]: app_dial.c:2527 dial_exec_full: Unable to create channel of type ‘PJSIP’ (cause 3 - No route to destination)
== Everyone is busy/congested at this time (1:0/0/1)
– Executing [16085------@from-internal:3] Progress(“SIP/1024-00000003”, “”) in new stack
– Executing [16085------@from-internal:4] Wait(“SIP/1024-00000003”, “1”) in new stack
> 0xb6324220 – Strict RTP switching to RTP target address as source
– Executing [16085------@from-internal:5] Playback(“SIP/1024-00000003”, “silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer”) in new stack
– Playing ‘silence/1.ulaw’ (language ‘en’)
– Playing ‘cannot-complete-as-dialed.ulaw’ (language ‘en’)
– Playing ‘check-number-dial-again.ulaw’ (language ‘en’)

Sorry its been about 6-7 years since ive tried IncrediblePBX, you might try asking over here:

When I first started using google voice I used IncrediblePBX for about a year or two. Then I had an issue, its been so long I can’t even remember what it was, I actually think it might have been when I switched from using pygooglevoice to GV motif, so I installed Freepbx distro, and I ran that for about the last 6 years without really any problems.

To just readover what you posted, one line seems to indicate that the ‘gvsip’ trunk is missing, however without having tried IncrediblePBX recently, I could not speculate why.

Now I am somewhat comfortable using Freepbx so it’s what I continue to use.

From what I can tell Incredible PBX seems to take a lot of the leg work out of setting things up, so I would have guessed it should have just worked without issue, hopefully somebody over on the PIAF forums can help, PIAF and incredible PBX are intertwined.(at least that’s my understanding.)

One could also modify the Google voice module to add everything that’s needed in here. Including adding the additional settings into pjsip. Only issue is being able to tell if it’s nafs version of asterisk.


Make samples has caused issues with freepbx installs in the past. Plus as dicko said there’s no reason to run it.

1 Like

My compliments on your efforts, you jumped in at the deep end, and we see you learning fast,watch out for any inappropriate slings and arrows that often come , just get it working, then reply to any critiques :slight_smile: