Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
PSTN or Public Switched Telephone Network is the collection of all the telephone networks, which are interconnected in the world. If we want to be able to route calls from and to the PSTN using OpenSER, we need to be connected to a PSTN. To send calls to the PSTN, we need a device called PSTN gateway. There are several manufacturers such as Cisco, Nortel, and others who manufacture this kind of equipment. You can also use an Asterisk PBX box for this task. Asterisk makes an affordable PSTN gateway that is very competitive with the big players mentioned above. In this article by Flavio E. Goncalves, we will see how to use asterisk as a PSTN gateway for OpenSER.
Using Asterisk as a PSTN Gateway
Step 1: Add the gateway address in the trusted table using SerMyAdmin:
If desired or convenient, you can instead use the MySQL command line interface to achieve the same result.
#mysql –u openser –p
-- enter your mysql password --
mysql> use openser;
mysql> INSERT INTO trusted ( src_ip, proto, from_pattern )
VALUES ( '10.1.30.22', 'any', '^sip:.*$');
The records above tell the OpenSER script to allow requests coming from the IP address 10.1.30.22 with any transport protocol, matching the regular expression ^sip:.*$. You can use the following command if you don't want to reload OpenSER.
#openserctl fifo trusted_reload
Step 2: Include your served domains in the domain table (if you have not done before).
openserctl domain add sermyadmin.org
You can also use SerMyAdmin to do this.
Step 3: Include the user into the groups (local, ld, and int):
#openserctl acl grant firstname.lastname@example.org local
#openserctl acl grant email@example.com ld
#openserctl acl grant firstname.lastname@example.org int
#openserctl acl grant email@example.com local
To use SerMyAdmin, just go to the screen below:
Step 4: Configuring Asterisk as a gateway.
Two very popular gateways for OpenSER are Asterisk and Cisco AS5300. Gateways from other manufacturers can be used too; check their documentation for instructions. Let's see how to configure a Cisco 2601 with two FXO interfaces and an Asterisk with an E1 PSTN card.
It is important to prevent the direct sending of SIP packets to gateways. The SIP proxy should be in front of the gateway and a firewall should prevent users from sending SIP requests directly to the gateway.
Step 5: Setting up the Asterisk Server or the Cisco Gateway.
We will assume that the PSTN side of the Asterisk gateway is already configured. Now let's change the SIP configuration (sip.conf) of our gateway and its dial plan (extensions.conf). We will configure Asterisk to send to the proxy each call coming from the PSTN and vice versa. We are using the guest feature of the SIP channel on the Asterisk Server. Prior knowledge of Asterisk is required here. Below is the simplest configuration allowing Asterisk to communicate with OpenSER. Please, adapt this script to your topology.
Allow SIP packets to your asterisk server, coming only from your SIP server. Do not allow SIP packets coming from other destinations. You can use IP Tables to do this, consult a Linux security specialist, if you are
Asterisk Gateway (sip.conf)
#calls incoming from the SIP proxy to be terminated in the PSTN lines
#calls incoming from the PSTN to be forwarded to clients behind the SIP
# If you have a digital interface use the lines below
#If you have analog FXO interfaces use the lines below.
Cisco 2601 Gateway
The following explanation could help, but prior knowledge of Cisco gateways is required to complete this configuration. The call routing on Cisco gateways is done by the instruction dial peer. Any call with the number called starting with 9 followed by any number (9T) is forwarded to the PSTN on the ports 1/0 or 1/1 as instructed by the dial peer voice 1 and 2 POTS lines (plain old telephone system). Called numbers starting from 1 to 9 with any number of digits following will be directed to the SIP proxy in the IP address 10.1.3.22 as instructed in the 'dial-peer voice 123 voip' line.
voice class codec 1
codec preference 2 g711ulaw
ip address 10.1.30.38 255.255.0.0
ip route 0.0.0.0 0.0.0.0 10.1.0.1
no ip http server
ip pim bidir-enable
mgcp profile default
! The dial-peer pots commands will handle the calls coming from SIP
!dial-peers. Any call matching 9 followed by any number of digits will
be !forwarded to the PSTN with the 9 striped.
dial-peer voice 1 pots
dial-peer voice 2 pots
!The dial-peer voip commands will handle the calls coming from the
pots !dial peers (PSTN). You can prefix a number (80 in this example)
and send the DID number ahead.
dial-peer voice 123 voip
session protocol sipv2
session target ipv4:10.1.30.22
Step 6: Test the configuration making and receiving calls.
In this article, we have seen how to configure and use the Cisco 2601 gateway and the Asterisk gateway for OpenSER to send calls to the PSTN.
If you have read this article you may be interested to view :
eBook Price: €0.00
Book Price: €0.00
About the Author :
Flavio E. Goncalves was born in 1966 in Minas Gerais, Brazil. Having always had a strong interest in computers, he got his first personal computer in 1983 and since then it has been almost an addiction. He received his degree in Engineering in 1989 with focus in computer aided design and computer aided manufacturing. He is also CEO of V.Office Networks in Brazil, a consulting company dedicated to the areas of Networks, Security, Telecom, and Operating Systems and a training center since its foundation in 1996. Since 1993, he has participated in a series of certification programs having being certificated as Novell MCNE/MCNI, Microsoft MCSE/MCT, Cisco CCSP/CCNP/CCDP, Asterisk dCAP, and some other.
He started writing about open-source software because he thinks the way certification programs were organized in the past was very good to help learners. Some books today are written by strictly technical people, who, sometimes, do not have a clear idea on how people learn. He tried to use his 15-year experience as instructor to help people learn open-source telephony software. His experience with networks, protocol analyzers, and IP telephony, combined with his teaching skills, gave him an edge to write this book. This is the second book he has written; the first one was The Configuration Guide for Asterisk PBX. As the CEO of V.Office, Flavio E. Goncalves balances his time between family, work, and fun. He is the father of two children and lives in Florianopolis, Brazil, in his opinion one of the most beautiful places in the world. He dedicates his free time to water sports such as surfing and sailing.
Books From Packt