This page gives a detailed insight into how to configure Asterisk for handling both incoming and outgoing calls from/to public phone networks. In my example the uplink is established via sipgate.de. There actually is no specific reason for using this service, except for the fact that it was quickly available during my initial setup.

As I’m not very familiar with working with Asterisk there will probably be nicer, better and more elegant solutions for what I’ve set up. Mine simply does the job.

Basics

In the following xxxUSERNAMExxx and xxxPASSWORDxxx are spacers for username and password for the sipgate.de account.

sip.conf

Two entries are necessary in /etc/asterisk/sip.conf to enable the outside connectivity.

The first one needs to be placed in the [general] block and triggers asterisk to establish a connection to sipgate.

register=xxxUSERNAMExxx:xxxPASSWORDxxx@sipgate.de/xxxUSERNAMExxx

The following exerpt defines the actual connection and the context for incoming calls.

[sipgate_out]
type=peer
defaultuser=xxxUSERNAMExxx
fromuser=xxxUSERNAMExxx
secret=xxxPASSWORDxxx
context=incoming
extension=xxxUSERNAMExxx
host=sipgate.de
dtmfmode=rfc2833
qualify=yes
fromdomain=sipgate.de
nat=no
directmedia=no
canreinvite=no
insecure=port,invite
allow=!all,alaw,g722

extensions.conf

The following excerpt from the [internal] block of my extensions.conf defines outgoing calls. As “internal might sound confusing while talking about external calling: The [internal] block defines calling rules for all my internally connected devices.

The lines are at the end of my [internal] block and match all calls to sequences of numbers. These are then brought into the SIP context and a call via sipgate is established. The value of “exten” here will be the number to which the call is established.

exten => _!X.,1,Set(CALLERID(num)=SIPID)
exten => _!X.,2,Dial(SIP/${EXTEN}@sipgate_out,30,trg)
exten => _!X.,3,Hangup

CallerID

The excerpt above will result in a call to the dialed extension and will show the number of the attached sipgate account as a source number. Doing hacks and demos this always looks strange, as the called person will directly see that something is strange. As such suppressing the source number can be very helpful. This can be done by adding *31_ to the second line.

exten => _!X.,2,Dial(SIP/*31${EXTEN}@sipgate_out,30,trg)