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
[sipproxy]#calls incoming from the PSTN to be forwarded to clients behind the SIP
[sipoutgoing]# 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.