
If you want to build your own VoIP phone system, Asterisk is one of the best open-source platforms to learn.
Asterisk can turn a Linux server into a complete PBX system capable of handling SIP extensions, inbound calls, outbound calls, IVR menus, voicemail, call queues, and many other VoIP features.
For businesses that need customized VoIP platforms, working with an experienced Asterisk development company can also help with system architecture, custom dialplan development, SIP integrations, and production deployment.
In this tutorial, we will build a basic Asterisk PBX from scratch and configure two SIP extensions that can call each other.
What Is Asterisk?
Asterisk is an open-source communications framework that can be used to build VoIP and PBX applications.
With Asterisk, you can create systems such as:
- IP PBX systems
- Business phone systems
- IVR systems
- Call centers
- Voicemail systems
- Call queues
- Conference systems
- SIP-based applications
- WebRTC calling applications
Asterisk works with protocols such as SIP and technologies such as RTP for handling voice communication.
For this tutorial, we will use PJSIP, the modern SIP channel driver in Asterisk.
What You Need
Before starting, you need:
- A Linux server
- Ubuntu 22.04 or Ubuntu 24.04
- Root or sudo access
- A public IP address if you want remote SIP clients
- Basic Linux command-line knowledge
- A SIP softphone such as Linphone, Zoiper, or MicroSIP
For testing, a small cloud VPS is enough.
You can also install Asterisk on a local virtual machine.
Asterisk Development Services
Once you understand the basic PBX setup, you can extend Asterisk into a customized communications platform.
Common Asterisk development services include:
- Custom PBX development
- SIP application development
- PJSIP integration
- IVR development
- Call routing development
- Call queue development
- Voicemail solutions
- SIP trunk integration
- WebRTC integration
- CRM and API integration
- Call center software development
- Asterisk migration and upgrades
- Custom dialplan development
These services are useful when a standard PBX configuration is not enough and the business requires custom call flows or integrations.
Step 1: Update Ubuntu
Connect to your server using SSH.
ssh username@your-server-ip
Update the package repository and installed packages:
sudo apt update
sudo apt upgrade -y
Install packages required for compiling Asterisk:
sudo apt install -y wget curl git build-essential \
libxml2-dev libncurses5-dev uuid-dev \
libjansson-dev libsqlite3-dev libssl-dev \
libedit-dev pkg-config
Step 2: Download Asterisk
Move to /usr/src:
cd /usr/src
Download the Asterisk source code:
sudo wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-22-current.tar.gz
Extract it:
sudo tar -xvzf asterisk-22-current.tar.gz
Enter the extracted directory:
cd asterisk-22.*
Step 3: Install Required Dependencies
Run the Asterisk prerequisite installation script:
sudo contrib/scripts/install_prereq install
Depending on your server, this may take several minutes.
Step 4: Configure Asterisk
Run:
sudo ./configure
Then open the module selection interface:
sudo make menuselect
For a basic PBX, make sure the required PJSIP, RTP, dialplan, voicemail, and music-on-hold components are available.
Save the configuration and exit.
Step 5: Compile Asterisk
Compile Asterisk:
sudo make -j$(nproc)
Install it:
sudo make install
Install sample configuration files:
sudo make samples
Install startup configuration:
sudo make config
Update shared libraries:
sudo ldconfig
Step 6: Create an Asterisk User
Create a dedicated system user:
sudo groupadd asterisk
sudo useradd -r -d /var/lib/asterisk -g asterisk asterisk
Change ownership:
sudo chown -R asterisk:asterisk /etc/asterisk
sudo chown -R asterisk:asterisk /var/{lib,log,spool}/asterisk
sudo chown -R asterisk:asterisk /usr/lib/asterisk
Step 7: Start Asterisk
Enable Asterisk at boot:
sudo systemctl enable asterisk
Start the service:
sudo systemctl start asterisk
Check the service:
sudo systemctl status asterisk
Step 8: Open the Asterisk CLI
Connect to the CLI:
sudo asterisk -rvvv
Check the version:
core show version
Check PJSIP endpoints:
pjsip show endpoints
Exit the CLI:
exit
Step 9: Configure PJSIP
We will create two SIP extensions:
1001
1002
Open:
sudo nano /etc/asterisk/pjsip.conf
Add your endpoint configuration:
[1001]
type=endpoint
context=internal
disallow=all
allow=ulaw
auth=1001-auth
aors=1001
[1001-auth]
type=auth
auth_type=userpass
username=1001
password=ChangeThisPassword1001
[1001]
type=aor
max_contacts=1
[1002]
type=endpoint
context=internal
disallow=all
allow=ulaw
auth=1002-auth
aors=1002
[1002-auth]
type=auth
auth_type=userpass
username=1002
password=ChangeThisPassword1002
[1002]
type=aor
max_contacts=1
Use strong passwords instead of the example credentials.
Step 10: Configure the Dialplan
Open:
sudo nano /etc/asterisk/extensions.conf
Add:
[internal]
exten => 1001,1,Dial(PJSIP/1001,20)
same => n,Hangup()
exten => 1002,1,Dial(PJSIP/1002,20)
same => n,Hangup()
This allows extension 1001 to call 1002 and extension 1002 to call 1001.
Step 11: Reload the Configuration
Open the CLI:
sudo asterisk -rvvv
Reload PJSIP:
pjsip reload
Reload the dialplan:
dialplan reload
Check endpoints:
pjsip show endpoints
Step 12: Configure Your SIP Softphone
For extension 1001:
Username: 1001
Password: Your password
Domain: YOUR_SERVER_IP
Port: 5060
Transport: UDP
For extension 1002:
Username: 1002
Password: Your password
Domain: YOUR_SERVER_IP
Port: 5060
Transport: UDP
After registration, check:
pjsip show contacts
Step 13: Make Your First Call
From extension 1001, dial:
1002
Asterisk should route the call to extension 1002.
You can watch the call activity directly from the Asterisk CLI:
sudo asterisk -rvvv
Step 14: Troubleshoot SIP
Check endpoints:
pjsip show endpoints
Check contacts:
pjsip show contacts
Inspect an endpoint:
pjsip show endpoint 1001
Enable SIP logging:
pjsip set logger on
Disable it after troubleshooting:
pjsip set logger off
Step 15: Configure the Firewall
If remote SIP clients need to connect, configure your firewall appropriately.
For example:
sudo ufw allow 5060/udp
Check your RTP configuration:
sudo nano /etc/asterisk/rtp.conf
A common RTP range may look like:
[general]
rtpstart=10000
rtpend=20000
If you use this range, configure your firewall accordingly.
Avoid exposing unnecessary ports to the public internet.
Step 16: Configure NAT
For endpoints behind NAT, settings such as these can help:
rewrite_contact=yes
rtp_symmetric=yes
force_rport=yes
NAT configuration depends on your network architecture and should be tested carefully.
If SIP registration works but you experience one-way audio, investigate RTP and NAT configuration first.
Step 17: Add Voicemail
Asterisk supports voicemail out of the box.
Open:
sudo nano /etc/asterisk/voicemail.conf
Example:
[default]
1001 => 1234,User 1001,user1001@example.com
1002 => 1234,User 1002,user1002@example.com
You can then add voicemail to your dialplan:
[internal]
exten => 1001,1,Dial(PJSIP/1001,20)
same => n,VoiceMail(1001@default,u)
same => n,Hangup()
Step 18: Build an IVR
Asterisk can also be used to build interactive voice response systems.
For example:
Press 1 for Sales
Press 2 for Support
Press 3 for Billing
A simple dialplan might look like:
[main-menu]
exten => s,1,Answer()
same => n,Playback(custom/main-menu)
exten => 1,1,Goto(internal,1001,1)
exten => 2,1,Goto(internal,1002,1)
Production IVRs should also handle timeouts, invalid input, retries, and fallback routing.
Common Asterisk CLI Commands
Some useful commands include:
core show channels
pjsip show endpoints
pjsip show contacts
pjsip show endpoint 1001
dialplan show internal
core show version
module show
dialplan reload
pjsip reload
pjsip set logger on
Learning these commands will make troubleshooting much easier.
Security Considerations
Never deploy a basic tutorial configuration directly to a production PBX.
Use:
- Strong SIP passwords
- Firewall rules
- SSH key authentication
- SIP access restrictions
- Outbound call restrictions
- Monitoring
- Rate limiting
- Regular updates
- Toll-fraud protection
An exposed PBX can become a target for SIP scanning and unauthorized outbound calls.
What Can You Build With Asterisk?
Once your basic PBX works, you can extend it into a much larger communications platform.
You can build:
- Business PBX systems
- Call center platforms
- IVR applications
- Auto attendants
- Call queues
- Conference systems
- SIP trunking solutions
- WebRTC applications
- Call recording systems
- CRM integrations
- Custom softphones
- Voice applications
- Automated calling systems
For complex projects, an experienced Asterisk development company can design the architecture and build custom integrations around your specific communication workflow.
Final Thoughts
Setting up Asterisk is an excellent way to understand how modern VoIP systems work.
Start with two SIP extensions, verify registration, make an internal call, and then gradually introduce features such as voicemail, IVR, queues, SIP trunks, and WebRTC.
A practical learning path is:
Linux
↓
Asterisk Installation
↓
PJSIP
↓
SIP Registration
↓
Dialplan
↓
Internal Calling
↓
RTP & NAT
↓
Voicemail
↓
IVR
↓
Queues
↓
SIP Trunks
↓
Production PBX
The key is to build incrementally and use the Asterisk CLI while testing each component.
Once you understand SIP signaling, RTP media, PJSIP endpoints, and the dialplan, you have the foundation needed to develop much more advanced VoIP applications and customized PBX solutions.
Top comments (0)