Asteriks +TLS+RSTP Encrypt on centos


this guide was gathered from official asteriks wikies (,,, and tested in VPS server with Centos 6 OS

first of all install libsrtp and libsrtp-devel

yum install libsrtp libsrtp-devel

If the packages cannot be found make sure you have epel repository installed.

Adding the repository

rpm -Uvh
yum update


yum install asterisk asterisk-configs --enablerepo=asterisk-11

install dahdi

yum install dahdi-linux dahdi-tools libpri

again upgrade

yum update

Basic configure add user accounts into the /etc/asterisk/sip.conf


secret=verysecretpassword ; put a strong, unique password here instead
;permit= ; replace with your network settings
secret=othersecretpassword ; put a strong, unique password here instead
;permit= ; replace with your network settings


We have commented deny/permit lines with ";" character coz we would like to allow users to access server from anywhere. BUT! Asterisks wiki told us:

Be Serious About Account Security We can't stress enough how important it is for you to pick a strong password for all accounts on Asterisk, and to only allow access from trusted networks. Unfortunately, we've found many instances of people exposing their Asterisk to the internet at large with easily-guessable passwords, or no passwords at all. You could be at risk of toll fraud, scams, and other malicious behavior. For more information on Asterisk security and how you can protect yourself, check out (c)

go to the Asterisk command-line interface. with simple command


make sip reload with next command:

sip reload

Create Dialplan Extensions. add these lines into /etc/asterisk/extensions.conf


The extension numbered 6001 which attempts to ring user1 phone for twenty seconds, and an extension 6002 which attempts to rings user2 phone for twenty seconds.

make dialplan reload in the Asterisk command line interface

 dialplan reload

You can verify that Asterisk successfully read the configuration file by typing dialplan show users at the CLI.

dialplan show users

You can now try to make test call using for example ExpressTalk software for windows (

As another option you can configure your users in /etc/asterisk/users.conf Here is the example with NAT enabled, codecs and other options just for example. Simply add these lines to users.conf: adding 1 user

 fullname = test1
 registersip = no
 host = dynamic
 callgroup = 1
 mailbox = 6100
 call-limit = 100
 type = peer
 username = 6100
 transfer = yes
 callcounter = yes
 context = DLPN_DialPlan1
 cid_number = 6100
 hasvoicemail = no
 vmsecret =
 email =
 threewaycalling = no
 hasdirectory = yes
 callwaiting = no
 hasmanager = no
 hasagent = no
 hassip = yes
 hasiax = yes
 secret = P@ssword1
 nat = yes
 canreinvite = no
 dtmfmode = rfc2833
 insecure = no       
 pickupgroup = 1
 requirecalltoken = yes
 macaddress = 6100
 autoprov = yes
 label = 6100
 linenumber = 1        
 LINEKEYS = 1    
 disallow = all 
 allow = ulaw,g729,alaw,gsm

if you want you can setup web gui for asteriks management regarding this guide: Also sometimes it's necessary to fix permissions for make GUI work:

sudo chown -R asterisk:asterisk /var/lib/asterisk/static-http/

Adding security

You should download Asterisk source code if you haven't download it before from Unzip it to some folder on your asterisk server.

tar -xvzf asterisk-11-current.tar.gz 

change dir to unzipped folder and run next command:

contrib/scripts/./ast_tls_cert -C -O "privatecompany" -d /etc/asterisk/keys

You'll be asked to enter a pass phrase for /etc/asterisk/keys/ca.key NOTE if you got hostname related error pls make next :

Generate a client certificate for our SIP device.

contrib/scripts/./ast_tls_cert -m client -c /etc/asterisk/keys/ca.crt -k /etc/asterisk/keys/ca.key -C -O "privatecompany" -d /etc/asterisk/keys -o sipuser1

you also will be prompted to enter passphrase for keys Create cert for users. after check that all key files should be in the key directory:


Configure Asterisk to use TLS: add/edit corresponding lines in sip.conf

tlsclientmethod=tlsv1 ;none of the others seem to work with Blink as the client

Next, you'll need to configure a SIP peer within Asterisk to use TLS as a transport type. add the line to your user/sip conf (it placed in sip.conf or in users.conf)

port=5061 # not neccessary but it will force use tls

Now you should copy keys from server to your client (pc or phone)

Now you should configure your sip client to use tls via port 5061.

How to make it depends from client you using.

We will add soon manual for android CSip client

TLS only encrypt extensions on the PBX we're dialing. We need to encrypt voice data with SRTP

Asteriks wiki told us: SRTP support is provided by libsrtp. libsrtp has to be installed on the machine before Asterisk is compiled, otherwise you're going to see something like: [Jan 24 09:29:16] ERROR[10167]: chan_sip.c:27987 setup_srtp: No SRTP module loaded, can't setup SRTP session. But we installed it at first steps in our man. so don't care.

Anyway if you got this in "asterisk -r" CLI during trying to make call do the next: install libsrtp (and the development header, and then reinstall Asterisk

go to you asterisk source code directory and run next commands:

make install

If you're getting errors during ./configure is running make sure you have these packages installed:

yum install gcc-c++ libtermcap-devel libxml2* sqlite-devel

Add the next line to your user config (in sip.conf or in users.conf)


Also better to force only one codec use:

disallow = all
;allow = ulaw,g729,gsm <--this line is commented!
allow = g722

You can also restart asterisk service for sure.

Was this answer helpful?

 Print this Article

Also Read


ConfigServer Security & Firewall (CSF) is a powerful iptables configuration tool....

Clear swap in Centos

Print memory usage [root@localhost]# free -m              total       used       free...

Autorun in Linux

To set a script to start at boot in CentOS, add it into /etc/rc3.d/S99local. For example:...

LXDE + xrdp

How to install Lightweight X11 Desktop Environment (LXDE) on Ubuntu. apt-get update...

Security tips for Linux server

1. Use only  strong passwords for all accounts , especially for root. Always use a secure root...