Asterisk is a powerful open-source VoIP (Voice over Internet Protocol) platform that enables you to set up your own telephony server for tasks like call routing, conferencing, and voicemail. This guide explains how to install and configure Asterisk on your VPS.
Why Choose Asterisk for VoIP?
- Highly Customizable: Asterisk allows for intricate call handling and routing.
- Open Source: No licensing fees for basic functionalities.
- Feature-Rich: Supports PBX systems, IVRs, and more.
- Scalable: Suitable for small businesses and large enterprises alike.
Prerequisites
- VPS: A Linux-based VPS (Ubuntu or CentOS preferred).
- Root Access: Required for installation.
- Updated System: Ensure your VPS is updated with the latest packages.
Step 1: Update Your System
Start by ensuring your server is up to date:
For Ubuntu/Debian:
sudo apt update && sudo apt upgrade -y
For CentOS:
sudo yum update -y
Step 2: Install Required Dependencies
Install tools and libraries required for Asterisk:
For Ubuntu/Debian:
sudo apt install wget build-essential git curl libxml2-dev libncurses5-dev uuid-dev libjansson-dev -y
For CentOS:
sudo yum groupinstall "Development Tools" -y
sudo yum install wget git ncurses-devel libuuid-devel jansson-devel libxml2-devel -y
Step 3: Download and Compile Asterisk
-
Navigate to your working directory:
cd /usr/src
-
Download the latest version of Asterisk:
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz
-
Extract the downloaded file:
tar -xzvf asterisk-20-current.tar.gz cd asterisk-20.*
-
Install additional build dependencies:
sudo contrib/scripts/install_prereq install
-
Configure and compile Asterisk:
./configure make menuselect
- In the menuselect interface, enable desired modules such as
CORE-SOUNDS-EN
(English sound prompts). - Exit and save changes.
- In the menuselect interface, enable desired modules such as
-
Build and install Asterisk:
make sudo make install sudo make samples sudo make config sudo ldconfig
Step 4: Configure Asterisk
1. Start the Asterisk Service
Enable and start the service:
sudo systemctl start asterisk
sudo systemctl enable asterisk
2. Verify Installation
Access the Asterisk CLI (Command Line Interface):
sudo asterisk -r
You should see the Asterisk CLI prompt (*CLI>
).
3. Set Up SIP Extensions
Edit the SIP configuration file:
sudo nano /etc/asterisk/sip.conf
Add the following for two test users:
[1001]
type=friend
host=dynamic
secret=your_password
context=internal
[1002]
type=friend
host=dynamic
secret=your_password
context=internal
4. Set Up Dial Plan
Edit the extensions.conf
file to define how calls are handled:
sudo nano /etc/asterisk/extensions.conf
Add the following:
[internal]
exten => 1001,1,Dial(SIP/1001)
exten => 1002,1,Dial(SIP/1002)
Reload Asterisk configuration:
sudo asterisk -rx "reload"
Step 5: Open Firewall Ports
Ensure your VPS allows traffic on VoIP-related ports:
For ufw (Ubuntu/Debian):
sudo ufw allow 5060/tcp
sudo ufw allow 5060/udp
sudo ufw allow 10000:20000/udp
sudo ufw reload
For firewalld (CentOS):
sudo firewall-cmd --permanent --add-port=5060/tcp
sudo firewall-cmd --permanent --add-port=5060/udp
sudo firewall-cmd --permanent --add-port=10000-20000/udp
sudo firewall-cmd --reload
Step 6: Test Your VoIP Server
- Install a softphone application on your PC or mobile device (e.g., Zoiper or Linphone).
- Configure the softphone to connect to your Asterisk server:
- SIP Username: 1001 or 1002.
- Password: As defined in
sip.conf
. - Server Address: Your VPS's public IP.
- Make a test call between extensions to confirm the setup.
Optional: Secure Your VoIP Server
- Use Strong Passwords: Avoid easy-to-guess SIP passwords.
- Enable Fail2Ban: Protect against brute force attacks.
sudo apt install fail2ban -y
/var/log/asterisk/messages
). - Use TLS and SRTP: Encrypt SIP traffic for additional security.
Conclusion
By following this guide, you’ve successfully installed and configured a VoIP server with Asterisk on your VPS. This setup can handle simple call routing or scale to more complex scenarios as your needs grow. Explore Asterisk’s documentation for advanced features like IVR, voicemail, and call queues.