Thursday, November 11, 2010

Asterisk Sip Configuration

Here is a basic sip.conf file:

[general]
context=default
srvlookup=yes

[john]
type=friend
secret=welcome
qualify=yes ; Qualify peer is no more than 2000 ms away
nat=no ; This phone is not natted
host=dynamic ; This device registers with us
canreinvite=no ; Asterisk by default tries to redirect
context=internal ; the internal context controls what we can do


The sip.conf file starts with a [general] section, which contains the channel settings and default options for all users and peers defined within sip.conf. You can override the default settings on a per-user/peer basis by configuring them within the user/peer definition.

Domain Name System Service records (DNS SRV records) are a way of setting up a logical, resolvable address where you can be reached. This allows calls to be forwarded to different locations without the need to change the logical address. By using SRV records, you gain many of the advantages of DNS, whereas disabling them breaks the SIP RFC and removes the ability to place SIP calls based on domain names. (Note that if multiple records are returned, Asterisk will use only the first.) DNS SRV record lookups are disabled by default in Asterisk, but it's highly recommended that you turn them on. To enable them, set srvlookup=yes in the [general] section of sip.conf.

Each connection is defined as a user, peer, or friend. A user type is used to authenticate incoming calls, a peer type is used for outgoing calls, and a friend type is used for both. The extension name is defined within square brackets ([]). In this case, we have defined the extension john as a friend.

A secret is a password used for authentication. Our secret is defined as welcome. We can monitor the latency between our Asterisk server and the phone with qualify=yes, thereby determining whether the remote device is reachable. qualify=yes can be used to monitor any end device, including other Asterisk servers. By default, Asterisk will consider an extension reachable if the latency is less than 2,000 ms (2 seconds). You can configure the time Asterisk should use when determining whether or not a peer is reachable by replacing yes with the number of milliseconds.

If an extension is behind a device performing Network Address Translation (NAT), such as a router or firewall, configure nat=yes to force Asterisk to ignore the contact information for the extension and use the address from which the packets are being received. Setting host=dynamic will require the extension to register so that Asterisk knows how to reach the phone. To limit an endpoint to a single IP address or fully qualified domain name (FQDN) , replace dynamic with the IP address or domain name. Note that this limits only where you place calls to, as the user is allowed to place calls from anywhere (assuming she has authenticated successfully). If you set host=static, the end device is not required to register.

We've also set canreinvite=no. In SIP, invites are used to set up calls and to redirect media. Any invite issued after the initial invite in the same dialog is referred to as a reinvite. For example, suppose two parties are exchanging media traffic. If one client goes on hold and Asterisk is configured to play Music on Hold (MoH), Asterisk will issue a reinvite to the secondary client, telling it to redirect its media stream toward the PBX. Asterisk is then able to stream music or an announcement to the on-hold client.

The primary client then issues an off-hold command in a reinvite to the PBX, which in turn issues a reinvite to the secondary party requesting that it redirect its media stream toward the primary party, thereby ending the on-hold music and reconnecting the clients.

Normally, when two endpoints set up a call they pass their media directly from one to the other. Asterisk generally breaks this rule by staying within the media path, allowing it to listen for digits dialed on the phone's keypad. This is necessary because if Asterisk cannot determine the call length, inaccurate billing can occur. Configuring canreinvite=no forces Asterisk to stay in the media path, not allowing RTP messages to be exchanged directly between the endpoints.

Asterisk will not issue a reinvite in any of the following situations:

*

If either of the clients is configured with canreinvite=no
*

If the clients cannot agree on a common set of codecs and Asterisk needs to perform codec conversion
*

If either of the clients is configured with nat=yes
*

If Asterisk needs to listen to Dual Tone Multi-Frequency (DTMF) tones during the call (for transfers or any other features)

Lastly, context=internal specifies the location of the instructions used to control what the phone is allowed to do, and what to do with incoming calls for this extension. The context name configured in sip.conf matches the name of the context in extensions.conf, which contains the instructions. More information about contexts and dialplans will be presented in the following chapter.

If you are configuring a number of clients with similar configurations, you can place like commands under the [general] heading. Asterisk will use the defaults specified in the [general] section unless they are explicitly changed within a client's configuration block.

No comments:

Post a Comment