Linux | Install and Configure Asterisk PBX on Ubuntu 24.04 / Debian 13
Asterisk is a powerful, open-source communications framework that transforms a standard Linux server into a comprehensive Private Branch Exchange (PBX). Key highlights of this guide include:
Capabilities: It supports SIP trunking, IVR, voicemail, and conferencing without the burden of per-seat licensing fees.
Version & Support: This guide focuses on Asterisk 22 LTS, the current Long-Term Support release, ensuring full support through October 2028.
Technical Scope: The tutorial covers installing Asterisk from source on Ubuntu 24.04 and Debian 13, including:
Compiling with PJSIP support.
Configuring SIP endpoints and dialplans.
Firewall configuration and softphone testing.
System Requirements & Preparation
OS & Hardware: A server running Ubuntu 24.04 LTS or Debian 13 with a minimum of 2 CPU cores and 1 GB RAM.
Connectivity: A Public IP address is required for remote SIP clients or trunking (essential for your Canada-to-Bangladesh link).
Security & Firewall: The following ports must be open to allow signaling and voice traffic:
5060/UDP (Standard SIP)
5061/TCP (Encrypted SIP/TLS)
10000-20000/UDP (RTP Media/Voice streams)
Domain & SSL (Optional): A registered domain name is recommended if you plan to implement TLS/SRTP for secure, encrypted calling in production.
Root or sudo privileges are required to perform the installation.
sudo -i
Step 1. Install Asterisk Build Dependencies
Asterisk is compiled from source, so we need development libraries and build tools. Start by updating the package index and installing the required packages.
apt update && apt upgrade -y
Install the core build tools and libraries Asterisk needs for compilation:
apt install -y build-essential git curl wget subversion \libncurses5-dev libssl-dev libxml2-dev libsqlite3-dev \uuid-dev libjansson-dev libedit-dev pkg-config \autoconf automake libtool unixodbc-dev libcurl4-openssl-dev \libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev \libsrtp2-dev libopus-dev libresample1-dev sox mpg123 \xmlstarlet bison flex
These cover everything from TLS support (libssl-dev) to codec libraries (opus, speex, vorbis) and the SRTP stack needed for encrypted media.
Step 2. Download and Compile Asterisk 22 LTS
Download the latest Asterisk 22 LTS tarball from the official download server. The asterisk-22-current link always points to the newest 22.x release.
cd /usr/srcwget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-22-current.tar.gztar xzf asterisk-22-current.tar.gzcd asterisk-22.*/
contrib/scripts/install_prereq install
./configure --with-jansson-bundled --with-pjproject-bundled
make menuselect.makeoptsmenuselect/menuselect --enable CORE-SOUNDS-EN-WAV --enable CORE-SOUNDS-EN-G722 \--enable MOH-OPSOUND-WAV --enable MOH-OPSOUND-G722 \--enable EXTRA-SOUNDS-EN-WAV --enable EXTRA-SOUNDS-EN-G722 \menuselect.makeopts
make -j$(nproc)
Compilation takes 10-15 minutes depending on your hardware. The -j$(nproc) flag uses all available CPU cores to speed things up.
Step 3. Install Asterisk on Ubuntu / Debian
Once compilation finishes without errors, install the binaries, modules, and sample configuration files:
make installmake samplesmake configmake install-logrotate
Here is what each target does:
- make install – copies binaries and modules to /usr/sbin/ and /usr/lib/asterisk/- make samples – installs sample configuration files to /etc/asterisk/- make config – installs the systemd service unit- make install-logrotate – sets up log rotation so /var/log/asterisk/ does not fill your disk
Create a dedicated system user for Asterisk. Running as a non-root user is a basic security requirement:
groupadd asteriskuseradd -r -d /var/lib/asterisk -g asterisk asteriskchown -R asterisk:asterisk /etc/asterisk /var/lib/asterisk /var/log/asterisk /var/spool/asterisk /var/run/asterisk /usr/lib/asterisk
Tell Asterisk to run as this user by editing the main configuration file:
vi /etc/asterisk/asterisk.conf
Find the (options) section and set the run user and group:
[options]runuser = asteriskrungroup = asterisk
Step 4. Configure PJSIP for SIP Connectivity
vi /etc/asterisk/pjsip.conf
[global]type = globaluser_agent = Asterisk PBX; === Transport - UDP on port 5060 ===[transport-udp]type = transportprotocol = udpbind = 0.0.0.0:5060external_media_address = 192.168.100.100external_signaling_address = 192.168.100.100local_net = 192.168.101.0/24local_net = 10.0.0.0/8; === Transport - TCP on port 5060 ===[transport-tcp]type = transportprotocol = tcpbind = 0.0.0.0:5060; === Transport - TLS on port 5061 (production recommended) ===;[transport-tls];type = transport;protocol = tls;bind = 0.0.0.0:5061;cert_file = /etc/asterisk/keys/asterisk.crt;priv_key_file = /etc/asterisk/keys/asterisk.key;method = tlsv1_2
vi /etc/asterisk/extensions.conf
[general]static = yeswriteprotect = no[globals][internal]; Internal extensions - dial any 3-digit extension (100-199)exten => _1XX,1,NoOp(Dialing extension ${EXTEN})same => n,Dial(PJSIP/${EXTEN},30,tTr)same => n,Voicemail(${EXTEN}@default,u)same => n,Hangup(); Voicemail access - dial *97exten => *97,1,VoiceMailMain(${CALLERID(num)}@default)same => n,Hangup(); Echo test - dial *60 to verify audio pathexten => *60,1,Answer()same => n,Echo()same => n,Hangup()
vi /etc/asterisk/pjsip.conf
; === Extension 100 ===[100]type = endpointcontext = internaldisallow = allallow = ulawallow = alawallow = g722allow = opusauth = 100-authaors = 100-aordirect_media = nortp_symmetric = yesforce_rport = yesrewrite_contact = yes[100-auth]type = authauth_type = userpassusername = 100password = ChangeMeNow100![100-aor]type = aormax_contacts = 3remove_existing = yesqualify_frequency = 30; === Extension 101 ===[101]type = endpointcontext = internaldisallow = allallow = ulawallow = alawallow = g722allow = opusauth = 101-authaors = 101-aordirect_media = nortp_symmetric = yesforce_rport = yesrewrite_contact = yes[101-auth]type = authauth_type = userpassusername = 101password = ChangeMeNow101![101-aor]type = aormax_contacts = 3remove_existing = yesqualify_frequency = 30
direct_media = no– forces media through Asterisk, which is essential when clients are behind NATrtp_symmetric = yesandforce_rport = yes– handle NAT traversal for both RTP and SIP signalingrewrite_contact = yes– rewrites the Contact header to the source address, fixing registration behind NATqualify_frequency = 30– sends OPTIONS pings every 30 seconds to keep NAT mappings alive and detect offline phonesmax_contacts = 3– allows the same extension to register from up to 3 devices simultaneously
vi /etc/asterisk/rtp.conf
[general]rtpstart = 10000rtpend = 20000
systemctl enable asterisksystemctl start asterisk
systemctl status asterisk
asterisk -rx "core show version"
asterisk -rvvv
ufw allow 5060/udp comment "SIP signaling"ufw allow 5060/tcp comment "SIP signaling TCP"ufw allow 5061/tcp comment "SIP TLS"ufw allow 10000:20000/udp comment "RTP media"ufw reload
iptables -A INPUT -p udp --dport 5060 -j ACCEPTiptables -A INPUT -p tcp --dport 5060 -j ACCEPTiptables -A INPUT -p tcp --dport 5061 -j ACCEPTiptables -A INPUT -p udp --dport 10000:20000 -j ACCEPTiptables-save > /etc/iptables/rules.v4
ss -ulnp | grep asterisk
Register a SIP softphone to verify the setup works. Popular free SIP clients include Linphone (Linux/Windows/Mac/mobile), MicroSIP (Windows), and Onaip (Android/iOS).
Configure the softphone with these settings:
- SIP Server / Domain: your server’s IP address or hostname
- Username: 100
- Password: ChangeMeNow100! (or whatever you set in pjsip.conf)
- Transport: UDP
- Port: 5060
After registering, check the registration status from the Asterisk console:
asterisk -rx "pjsip show endpoints"
You should see your registered endpoint with status “Avail” (available). To verify audio, dial *60 from the softphone – this runs the echo test. Everything you say should echo back to you after a short delay.
If registration fails, check the Asterisk log for details:
tail -50 /var/log/asterisk/messages
Common registration issues include wrong passwords, firewall blocking port 5060, or NAT settings misconfigured in the transport section. Make sure external_signaling_address in pjsip.conf matches your server’s actual public IP.
To test internal calling, register a second softphone as extension 101 and dial 100 from it. The phone on extension 100 should ring for 30 seconds as defined in the dialplan.
Step 10. Install FreePBX Web GUI (Optional)
If you prefer managing Asterisk through a web interface instead of config files, FreePBX provides a full-featured GUI on top of Asterisk. It handles extensions, trunks, IVR menus, ring groups, and call recording through a browser.
Install the web server and PHP dependencies FreePBX needs:
apt install -y apache2 mariadb-server mariadb-client \php php-cli php-mysql php-gd php-curl php-mbstring \php-xml php-zip php-bcmath php-intl \nodejs npm
systemctl enable --now mariadb apache2
cd /usr/srcwget https://github.com/FreePBX/framework/archive/refs/heads/release/17.0.zip -O freepbx-17.zipunzip freepbx-17.zipcd framework-release-17.0./install -n --dbuser=root
Your Asterisk 22 LTS is now operational on Ubuntu 24.04 or Debian 13. With the core framework in place, you can now transition from a basic setup to a production-ready communication system.
Key Expansion Options:
Feature Richness: Integrate SIP trunks from your ITSP (like the AWS SIP stack), configure IVRs, voicemail-to-email, and call recording.
Security & Encryption: For production, TLS/SRTP is essential for encrypting both signaling and voice media.
Proactive Defense: Implement Fail2Ban to automatically block SIP brute-force attempts.
Monitoring & Maintenance: Use AMI (Asterisk Manager Interface) or SNMP for real-time monitoring, and ensure regular database backups are scheduled.
No comments:
Post a Comment