Asterisk is an open-source IP PABX, meaning it lets you run a phone system over your computer network. Whilst IP telephony has been gaining the upper hand over traditional PABX’s for years, few people outside the industry realise just how easy it is to set up your own phone server.
With this guide, you can turn any Linux device into your own PABX for free. We’ll set up two SIP devices on a small network, so that they can dial each other.
Prepare the environment
First, you should get something with Linux. A virtual machine, a spare laptop, a Raspberry pi- anything.
Install asterisk with one of the following commands, depending on your distribution:
apt-get install asterisk
yum install asterisk
If you don’t have an IP phone handy, then you need a program on your computer which speaks SIP (Session Initiation Protocol). This guide uses Linphone (available for Linux and Windows among other platforms) and the Polycom 331 as examples, but any two SIP endpoints will work just as well for testing.
Make users on the server
Asterisk keeps its configuration in /etc/asterisk. The file we need to edit for this setup is users.conf. Open it up with your favourite text editor:
nano /etc/asterisk/users.conf
The syntax is similar to .ini files. Add two users to the bottom of the file:
[6001]
fullname = Example Bob
secret = 1234
hassip = yes
context = users
host = dynamic
[6002]
fullname = Example Joe
secret = 1234
hassip = yes
context = users
host = dynamic
What does this mean?
- [600..]
- This is the username, and will become the user’s extension on our small network. Dial 6001 for Bob or 6002 for Joe. Whilst 'bob' and 'joe' could also be used here, numeric usernames are more common.
- fullname = ...
- Used in the Caller ID.
- secret = ...
- The password used to log in. In a secure system, you would use something other than 1234!
- hassip = yes
- This tells Asterisk to make a SIP account for the user. Asterisk supports a few other account types, but SIP is the most widely implemented.
- context = users
- A context is a bit like a category for the user. The extensions which they can dial depend on this.
- host = dynamic
- This tells Asterisk that the users don’t have a fixed IP address. This means that they must register periodically with the SIP server so that their IP is known.
To activate these changes, save the file, and reload the configuration through the Asterisk console:
mike# asterisk -r -vvvvvvvvv
CLI> reload
CLI> sip show users
Username Secret Accountcode Def.Context ACL ForcerPort
6002 1234 users No Yes
6001 1234 users No Yes
All of those v‘s stand for verbose, meaning that the asterisk console will give you more information.
Configure the clients
First you should find out your server’s IP address. From the terminal, you can find this with:
ifconfig
Setting up “Example Joe” on a Linphone instance only takes a few clicks. Add a new account, with 6002 as the identity, and your asterisk server as the proxy address (eg: sip://voip.example.com). Click the image below for an example:
Meanwhile, the Polycom 331 can be configured as “Example Bob” by navigating the menus on the phone itself, or via the web (suggested). The default login is:
- Username:
- Polycom
- Password:
- 456
Your asterisk server address needs to be added under SIP -> Servers -> Server 1, while Example Bob’s identity is added under Lines -> Line1. Click the below images for an example.
Once these are saved, the two clients will register with the server. In SIP, clients periodically register so that the server knows where to find them.
In the asterisk console, you will see something like this:
-- Registered SIP '6001' at 192.168.1.4:5060
> Saved useragent "PolycomSoundPointIP-SPIP_331-UA/3.3.3.0069" for peer 6001
If registration fails, the console will tell you why, provided that you have set the verbosity high enough
You can check which users have registered with this command:
CLI> sip show peers
Name/username Host Dyn Forcerport ACL Port Status
6001/6001 192.168.1.4 D N 5060 Unmonitored
6002 (Unspecified) D N 0 Unmonitored
2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 1 online, 1 offline]
Unfortunately, even after both users have registered, they aren’t ready to communicate yet.
Add extensions to the server
In the world of VOIP, an extension is not a real loop of copper, but a sequential list of things to do when a number is dialled.
This extra step is where Asterisk gets its flexibility. With your extensions.conf setup, you could set your instance to redirect numbers, or dial for 12 seconds before going to voicemail.
We haven’t told the server what to do, so if “Example Bob” makes a call, it wont work yet:
== Using SIP RTP CoS mark 5
[Nov 15 07:59:30] NOTICE[6070]: chan_sip.c:22753 handle_request_invite: Call from '6001' (192.168.1.4:5060) to extension '6002' rejected because extension not found in context 'users'.
To add extensions, open extensions.conf up:
nano /etc/asterisk/extensions.conf
The syntax is still INI-like. Under [users], we add the steps for each extension, numbered sequentially. In this case, there is only 1 step for each extension: to dial a SIP user.
[users]
exten => 6001,1,Dial(SIP/6001)
exten => 6002,1,Dial(SIP/6002)
In the Asterisk console, type reload to activate the changes.
Now, as planned, both users on the network can dial each-other and have a chat.
More advanced setups
Ok, time to do a reality check. You’ve built an intercom, but not a full phone system! For a start, you need a way to dial the outside world, and let the outside world dial you. For this, you’ll need to work with hardware and service providers.
Hi,
Can you please post the lines of sip.conf file
We have a problem connecting from remote client
Thanks,
Mohammed
@Mohammed: For this particular setup, the sip.conf was not modified from the default that shipped with Debian. hassip = yes in users.conf was all that was used to enable SIP for them.
Because this “getting started” post covers only a very simply setup, it’s likely that you will need to consult some other resources on the web for debugging your connection issue.
Best of luck!
hi
i installed asterisk on centos 7(that is my server) and i want to call or message with linphone
i can’t call or message on linphone
when send a message then show “Message not sent”
thanks
@ahberyani – These instructions were written some time ago, and would have been tested on Debian 6. In your case, Centos7 has a firewall and SELinux so definitely check the log files.
If you get it working, post back and I’ll incorporate your solution into the guide for future readers.
Hello,
This was clear, short and easy to follow.
Thank you Mike!
I can only call one way, 6002 can call 6001 but not the other way.
Thank you, it was clear!
I tester it with few granstream phones..
Where is that intercom “More advanced setups” which you mentioned. Way to dial the outside world, and let the outside world dial you.
Also i can not get video between 2 grandstream telephones, when i using another SIP server (kamailio) i have video.
@sebastian I wonder if you have found resolution to your issue. Please share on the comment section if possible. Thank you.
Regards,
Daniel
Hi Mike
I know this post is a bit old, but I still wanted to thank you a lot for this wonderfull How-To. It just works like a charm in 2019 with an up to date Debian, softphones and IP Phones like Linksys’s I had to make a ToIP demo in a short time, you really saved my day !
Best Regards,
Eric
Linphone setup example is useless – totally different than current linphone setup – it’s gone “Simplified”.
This tutorial is useless now
Hi ,
can any tell me what is difference between [6001] section name and username in section name in sip.conf?
Instant SIP/2.0 401 Unauthorized reply from the server after following these steps. Meh.
@B Keyport: It is NOT useless for someone who wants to set up a very simple asterisk installation. In this case, this is still working (Kubuntu 19.10, Asterisk 16.2.1, Linphone 4.1.1/3.12) and easy and well explained. Got mine running in under five minutes. If you are not able to setup linphone, you should try google ;)
@Mike: thank you! ;)
THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
After struggling through all of the poorly written Asterisk docs and tutorials, this one actually got me talking between two phones in about 10 minutes!