4 min read

Using Asterisk as a PSTN Gateway

Step 1: Add the gateway address in the trusted table using SerMyAdmin:

Using Asterisk as a PSTN Gateway for OpenSER

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.

Using Asterisk as a PSTN Gateway for OpenSER

Step 3: Include the user into the groups (local, ld, and int):

#openserctl acl grant [email protected] local
#openserctl acl grant [email protected] ld
#openserctl acl grant [email protected] int
#openserctl acl grant [email protected] local

To use SerMyAdmin, just go to the screen below:

Using Asterisk as a PSTN Gateway for OpenSER

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.

Warning
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.

Warning
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
in doubt.

Asterisk Gateway (sip.conf)

[general]
context=sipincoming
#calls incoming from the SIP proxy to be terminated in the PSTN lines
[sipproxy]
#calls incoming from the PSTN to be forwarded to clients behind the SIP
#proxy
type=peer
host=10.1.30.22
Asterisk (extensions.conf)
[general]
[globals]
[sipincoming]
exten=>_[0-9].,1,Dial(Zap/g1/${EXTEN:1})
exten=>_[0-9].,2,hangup()
[sipoutgoing]
# If you have a digital interface use the lines below
exten=_[0-9].,1,Answer()
exten=_[0-9].,2,dial(SIP/${EXTEN}@sipproxy)
exten=_[0-9].,3,Hangup()
#If you have analog FXO interfaces use the lines below.
exten=s,1,Answer()
exten=s,2,dial(SIP/${EXTEN}@sipproxy)
exten=s,3,Hangup()

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
!
interface Ethernet0/0
ip address 10.1.30.38 255.255.0.0
half-duplex
!
ip classless
ip route 0.0.0.0 0.0.0.0 10.1.0.1
no ip http server
ip pim bidir-enable
!
voice-port 1/0
!
voice-port 1/1
!
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
destination-pattern 9T
port 1/0
!
dial-peer voice 2 pots
destination-pattern 9T
port1/1
!
!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
destination-pattern ....T
prefix80
forward all
session protocol sipv2
session target ipv4:10.1.30.22
dtmf-relay sip-notify

Step 6: Test the configuration making and receiving calls.

Summary

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here