How to install Asterisk on Ubuntu 20.04

s2 0

Asterisk is a popular open source PBX platform for developing communications applications such as conference servers and VoIP gateways. It is used by individuals, small businesses, large corporations, and governments around the world.

Asterisk features include voicemail, music on hold, conference calling, call queuing, call recording, interactive voice response, text messaging, and more.

This tutorial explains how to install Asterisk on Ubuntu 20.04.

Ubuntu repositories contain an older version of Asterisk. We install the latest Asterisk from the source code.

requirements

Install the following packages required to download and build Asterisk:

sudo apt updatesudo apt install wget build-essential git autoconf subversion pkg-config libtool

Installation of DAHDI and LibPRI

DAHDI is a suite of drivers and utilities that enable Asterisk to communicate with analog and digital phones. The LibPRI library enables Asterisk to communicate using ISDN connections. If you do not need these libraries, you can skip this section.

Switch to /usr/src Directory and download and install DAHDI:

cd /usr/src/sudo git clone -b next git://git.asterisk.org/dahdi/linux dahdi-linuxcd dahdi-linuxsudo makesudo make install
cd /usr/src/sudo git clone -b next git://git.asterisk.org/dahdi/tools dahdi-toolscd dahdi-toolssudo autoreconf -isudo ./configuresudo make installsudo make install-configsudo dahdi_genconf modules

Run the following commands to create LibPRI:

cd /usr/src/sudo git clone https://gerrit.asterisk.org/libpri libpricd libprisudo makesudo make install

Install Asterisk

Clone the Asterisk source in the /usr/src Directory:

cd /usr/src/sudo git clone -b 18 https://gerrit.asterisk.org/asterisk asterisk-18

At the time of writing, the latest version of Asterisk is 18.x. When a new version is available, change the branch number in the command above.

Before proceeding with the next steps, change to the Asterisk source directory:

cd asterisk-18/

Download the MP3 sources required to create the MP3 module and use MP3 files on Asterisk:

sudo contrib/scripts/get_mp3_source.sh

Run the install_prereq Script to install the required dependencies:

sudo contrib/scripts/install_prereq install

the configure The script performs several checks to ensure that all dependencies on your system are in place. Run the script by typing:

sudo ./configure

In the next step, select the modules that you want to compile and install. Access menuselect by typing:

sudo make menuselect

Select the “format_mp3” option to tell Asterisk to create the MP3 module:

When you are done, switch to the “Save and Exit” button and press “Enter”.

Start the compilation process:

sudo make -j2

Compilation may take some time depending on your system. You can change that -j Flag corresponding to the number of cores in your processor.

When you’re done, install Asterisk and its modules by typing:

sudo make install

You can either install the generic configuration files with reference documentation by typing:

sudo make samples

Or install the basic PBX configuration files:

sudo make basic-pbx

The final step is to install the Asterisk init script by typing:

sudo make config

It is also a good idea to run ldconfig To update the shared library cache:

sudo ldconfig

Create Asterisk users

By default, Asterisk runs as the root user. We’ll create a new system user and for security reasons configure Asterisk to run as a newly created user.

Run the following command to create a new system user named. to create asterisk:

sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk

How to configure Asterisk to run as a asterisk User, open the /etc/default/asterisk File and uncomment the following two lines:

sudo nano /etc/default/asterisk
/ etc / default / asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"

add the asterisk User to dialout and audio Groups:

sudo usermod -a -G dialout,audio asterisk

We also need to change the ownership and permissions of all Asterisk files and directories so that the Asterisk user can access these files:

sudo chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisksudo chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk

Start Asterisk

Now that you’ve all set up, start the Asterisk service with the following command:

sudo systemctl start asterisk

To verify that Asterisk is running, connect to the Asterisk command line interface (CLI) by typing:

sudo asterisk -vvvr

You will see the standard Asterisk CLI prompt:

Connected to Asterisk GIT-18-263f906af4 currently running on ubuntu2004 (pid = 91303)
ubuntu2004*CLI>

The final step is to enable the Asterisk service to start at boot with:

sudo systemctl enable asterisk

Configure the firewall

The firewall protects your server from unwanted data traffic.

If you haven’t configured a firewall on your server, you can read our guide on setting up a firewall with ufw on Ubuntu

By default, SIP uses UDP port 5060 to open the port run:

sudo ufw allow 5060/udp

If you have activated the Real Time Protocol (RTP), you also have to open the following port range:

sudo ufw allow 10000:20000/udp

Feel free to adapt the firewall to your needs.

diploma

We showed you how to install the latest version of Asterisk from source on Ubuntu 20.04.

To learn more about configuring and using Asterisk, check out the official documentation
and

If you run into any problem or have any feedback, please leave a comment below.