- 2.1 Installing Asterisk on the Server
- 2.2 Calling "Hello World" from the CLI
- 2.3 Calling "Hello World" with a SIP Phone
- 2.4 Building a Minimal Phone System with Two SIP Phones
- 2.5 Rights Administration with Contexts
- 2.6 Calls to and from the Public Switched Telephone Network
2.6 Calls to and from the Public Switched Telephone Network
In this section, we connect our mini-system to the public switched telephone network (PSTN). Once we've done that, we can make and receive calls using our attached SIP phones.
2.6.1 Calling the PSTN
At this point, you have a working telephone system, which, although exciting, is not really useful, because it has no connection with the outside world. With just ten more minutes and a working Internet connection, you can have a working connection to the PSTN. To do this, you need an account with a SIP provider.
We will configure Asterisk so that you can make calls to the PSTN with the phones 2000 and 2001. First, the provider account must be defined in /etc/asterisk/sip.conf:
[general] port = 5060 bindaddr = 0.0.0.0 context = other register => 17984512232:UHDZJD@my-voip-provider.com/17984512232 ; ^ ^ ^ ^ ; | | | | ; user password provider user [2000] type=friend context=my-phones secret=1234 host=dynamic [2001] type=friend context=my-phones secret=1234 host=dynamic [ext-sip-account] type=friend context=from-voip-provider username=17984512232 fromuser=17984512232 secret=UHDZJD host=my-voip-provider.com fromdomain=my-voip-provider.com qualify=yes insecure=port,invite nat=yes
You must obtain the username (17984512232 in our example) and password (UHDZJD in our example) from the SIP provider; often you can do this through the provider's customer website. Asterisk needs this information to register with the provider and make calls.
Next we need an additional dialplan rule to allow outbound calls:
[other] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _X.,1,Dial(SIP/${EXTEN}@ext-sip-account)
After these new entries have been entered, save the file and start Asterisk as before, with asterisk -vvvvvc so that we get the Asterisk console. Wait a few seconds for the SIP phones to register. Now simply dial a number.
If everything is working as it should, you will hear the remote line ringing and be able to observe the call progress in the console.
It's a bit early to explain exactly how this works, but you'll read more about that later.3
2.6.2 Taking Calls from the PSTN
The last step is a small one: We want to be able to take incoming calls via our SIP provider on extension 2000. To do this, we need to add another context to /etc/asterisk/extensions.conf:
[other] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _X.,1,Dial(SIP/${EXTEN}@ext-sip-account) [from-voip-provider] exten => 17984512232,1,Dial(SIP/2000)
In our example, the number 17984512232 is the PSTN number (also called a DID or DN; more on that later) given to your account by your SIP provider. That the DID corresponds to the username is coincidental; it doesn't have to.
You can, of course, configure voicemail for calls coming in from the PSTN:
[other] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _0[1-9].,1,Dial(SIP/${EXTEN}@ext-sip-account) [from-voip-provider] exten => 17984512232,1,Dial(SIP/2000,20) exten => 17984512232,2,VoiceMail(2000,u)
If you were so inclined, you could just leave things like this and start using your new mini-PBX. But what fun would that be? This chapter was only meant to show you how quickly you can build a working Asterisk system. In the coming chapters, we fill in the gaps and show you just how much you can really do with Asterisk.