VoIP Phones - Asterisk

From AAISP Support Site
Revision as of 11:04, 8 August 2013 by Admin (talk | contribs)

Asterisk logo.png

  • IPv6 Works!

Asterisk is extremely flexible and covering different uses for it is outside the scope of this example as the setup used here was very basic.

Define proxies for inbound calls

Some background first:

Asterisk performs a forward DNS lookup on incoming calls. This means that even where the Asterisk box has registered, if the call comes in from the IP it registered to on a dual stack box but the lookup returns the other IP, Asterisk gets confused about where to route the call. It does not seem to cache the IP address it finds for the duration of the TTL either, so you can register one minute, then have a call from the same IP fail the next.

Unfortunately the only way around this seems to be to define a peer for each potential IP address that a call can come from. We only have two live "voiceless" servers at present (and a third test box) but it means that as we expand the service in future Asterisk users would have to keep updating their SIP configs. We therefore created a list of 10 servers (C and onwards are just A records pointing to the A server for now). Sadly this means that we needed to created 20 peers as they will all be dual stack!

If your Asterisk box is not dual stack you only need to include the IPv4 or IPv6 hostnames; whichever you're using.

If you are not registering (recommended unless you're on a dynamic IP or behind NAT) you will need to set up the username, password and host name for the trunk in the "SIP to your server" settings on the control pages.

Here is what the config looks like for a dual stack Asterisk box on static public IPs:

; Config for inbound calls
[common](!)
type=peer
; The following 2 values are set in the "SIP to your server" trunk settings on the control pages.
; They should be commented out, and trunk settings removed from the control pages, if using Asterisk to register to the far end.
fromuser=voiceless-in ; Their user for authenticating with us. 
secret=incomingpass ; Their password for authenticating with us
context=voiceless-in
insecure=invite
transport=udp
disallow=all
allow=alaw

; IPv4 hostnames
[voiceless-1](common)
host=a4.voiceless.aa.net.uk
[voiceless-2](common)
host=b4.voiceless.aa.net.uk
[voiceless-3](common)
host=c4.voiceless.aa.net.uk
[voiceless-4](common)
host=d4.voiceless.aa.net.uk
[voiceless-5](common)
host=e4.voiceless.aa.net.uk
[voiceless-6](common)
host=f4.voiceless.aa.net.uk
[voiceless-7](common)
host=g4.voiceless.aa.net.uk
[voiceless-8](common)
host=h4.voiceless.aa.net.uk
[voiceless-9](common)
host=i4.voiceless.aa.net.uk
[voiceless-10](common)
host=j4.voiceless.aa.net.uk

; IPv6 hostnames
[voiceless-11](common)
host=a6.voiceless.aa.net.uk
[voiceless-12](common)
host=b6.voiceless.aa.net.uk
[voiceless-13](common)
host=c6.voiceless.aa.net.uk
[voiceless-14](common)
host=d6.voiceless.aa.net.uk
[voiceless-15](common)
host=e6.voiceless.aa.net.uk
[voiceless-16](common)
host=f6.voiceless.aa.net.uk
[voiceless-17](common)
host=g6.voiceless.aa.net.uk
[voiceless-18](common)
host=h6.voiceless.aa.net.uk
[voiceless-19](common)
host=i6.voiceless.aa.net.uk
[voiceless-20](common)
host=j6.voiceless.aa.net.uk

Define a proxy for outbound calls

Defining us as a SIP proxy for outbound calls:

; Config for outbound calls.
[voiceless-out]
type=peer
remotesecret=outgoingpass             ; Our password to their service
defaultuser=+441234567890         ; Authentication user for outbound
host=voiceless.aa.net.uk


Registration

If you're behind NAT it is helpful to make Asterisk register. It re-registers every 120 seconds by default anyway so should keep NAT sessions open. You can register (and tell Asterisk that it's behind NAT) with these settings under the [general] section:

localnet=10.0.0.0/8
register => +441234567980:outgoingpass@voiceless.aa.net.uk/extn

In this example, extn is the extension that Asterisk will pass the call to. Asterisk matches the hostname against the peers later on in the config and so the only change you have to make is to remove the fromuser and secret from the [common] template in the inbound proxy example above. Localnet should of course be set to whatever RFC1918 range you are using on your LAN.


Define a proxy

Defining us as a SIP proxy for outbound calls:

[voiceless]
type=peer                        ; Only for outbound calls
remotesecret=password             ; password
defaultuser=+44123456789         ; Auth username
fromdomain=Asterisk  ; Might be good to put your hostname here.
host=voiceless.aa.net.uk
transport=udp
disallow=all
allow=alaw

Dialplan

To make this work in a real dialplan you will want something like the following examples in extensions.conf. See Asterisk's included example sip.conf for examples of how to send the call to different contexts etc. For outbound calls:

exten => _[+X].,1,Dial(SIP/voiceless-out/${EXTEN})

For inbound calls (assuming you're routing call to a registered Snom):

[voiceless-in]
exten => _[+X].,1,Dial(SIP/snom)

Test server

We have a test server for debugging problems and testing new features. If you wish to allow our test server to make calls in to you as well, you can include its IPs by defining these peers too:

; Test server IPv4 hostname
[voiceless-test4](common)
host=z4.voiceless.aa.net.uk

; Test server IPv6 hostname
[voiceless-test6](common)
host=z6.voiceless.aa.net.uk

Further Help

Customers using Asterisk and AAISP have created a website and IRC channel especially for this!