Linux IAX2, SIP, ENUM, Asterisk setup and configuration

Updated: 2005-03-24
Created: 2005-03-22

Licensing and disclaimer of warranty

Overview and terminology

IAX2 SIP, and ENUM are somewhat related standards for telecommunications over an internet (or the Internet) and between that and a PSTN, either public or private.

Telecommunications happens between endpoints, which are usually software or hardware devices, happens as sessions, each of which has a metadata and data side to it, and open, transfer and close phase, and sessions among endpoints are often, but not necessarily, mediated by switches, which perform a role similar to that of routers in networking or proxies in HTTP sessions.

Opening a sessions is often referred to as a call, because typically one endpoint calls the other, either directly or via one or more switches.

Sessions may be opened between two or more endpoints directly, in which case there is a direction connection between the endpoints, or via one or more switches, which relay the session to each other over more than one connection. The mechanisms that support connections are called transports, and usually these are either some IP based protocol, or an internal or external phone system, interfaced usually via a network card or a POTS/ISDN card.

Endpoints and switches must have at least one address (for example, a wall socket number for a phone), that allows them to be connected to, and the called endpoint usually also has one or more names; names usually are simple strings or numbers, or more commonly they have a hierarchical structures, usually as URI strings or ITU E.164 numbers.

If a session is opened via a switch, the switch may then continue to act as an intermediary, or only for the session itself but not for the data communicated over the session, or neither, handing further maintenance of the session and the transfer of data directly to the endpoints.

There are several conditions for a sessions to be established:

As a rule endpoint addresses are not used directly to start sessions but resolved from endpoint names when connections need to be established. Switches usually resolve endpoint names before connecting sessions to them. A switch usually has a list of the names and addresses of some endpoints, and a list of switches each of which has its own list of known endpoints; as a rule name to address resolution is then hierarchical based on the hierarchical structure of most names.

IAX2 and SIP are protocols used in opening a session, and ENUM is a convention that allows using the IP DNS to turn PSTN style location information like ITU E.164 telephone numbers into the address of an endpoint or a switch, that is usually an IP address.

A multiprotocol switch is one that mediates sessions over multiple protocols, and a transparent multiprotocol switch is one that can use different protocols for caller and callee connections converting them as necessary.

The following notes will discuss in some detail the structure configuration and operation of Asterisk, a transparent multiprotocol switch program, which supports both the IAX2 and SIP protocols, and the PSTN sessions, in any combination on the caller and callee side.

Structure of Asterisk

Asterisk is a transparent multiprotocol switch, and therefore it can help endpoints open sessions even if they don't have common connection protocols.

This means that a PSTN endpoint can call a SIP endpoint or a IAX2 endpoint or PSTN one via Asterisk, with the caller using GSM data compression and the callee expecting H.723 data compression, or any other combination.

Extensions and the dialplan

Sessions mediated by Asterisk are usually opened after an endpoint calls an Asterisk instance and presents a request to mediate a session to a named endpoint. In Asterisk configurations endpoint names are called extensions.

Asterisk does not have any builtin rules or restrictions on the syntax of an extension or its lexicon, but usually extensions have the same syntax as ITU E.164 numbers, and the same lexicon, which is the 10 digits plus octothorpe (#), asterisk (*) and the letters A, B, C and D (the letters are never used, so ignore them).

Extensions however cal also be arbitrary strings, and these are often used to name endpoints that are meant to be called only over IP, as most IP based protocols allow strings as endpoint names. A typical use is for online void chat rooms.

An Asterisk dialplan is contained in a file called usually extensions.conf and consists of a set of contexts each of which contains a sequence of rules specifying precisely how to satisfy a request to open a session to a particular extension or group of extensions.

A call to an extension is usually satisfied by either:

Endpoints and channels

Each type of endpoint is handled by a module for that channel.

An important aspect of Asterisk is that it is not just multiprotocol and transparent at that, but that it is also perfectly symmetrical among its channels, in that by itself it does not restrict which endpoints it can switch between.

However, as a rule, the user of an Asterisk instance will want to partitions endpoints in at least two classes, internal and external, and configure it so as allow internal endpoints to call other internal endpoints, or external points, an external endpoints to call internal endpoints, but not to allow external endpoints to call other external endpoints via the Asterisk instance. The reason for this is that for Asterisk to connect sessions to external endpoints usually involves some cost.

Endpoints belong to channels, and each channel's module has its own configuration, contained for example in a file called iax.conf for IAX2 endpoints and sip.conf for SIP endpoints.

These configurations consist of a set of endpoint definitions (which can be other switches); each definition usually contains some form of endpoint identification, an extension that is its name, and the name of a context in the dialplan to be used to switch calls incoming from that endpoint.

As a rule, only internal endpoints and switches will be listed in a channel configuration: when a call is received by Asterisk, the target extension will be classified in the dialplan as either the label for an internal endpoint, and then it will be forwarded to that endpoint, or for an external one, and then the dialplan will indicate an external switch to which the call can be relayed.

Session operation

After a session has been opened the session data can then flow among the endpoints, passing either via the switches involved in its opening or directly among the endpoints, if this is possible and allowed.

Apart from converting session data if required, Asterisk usually does not participate in a session once fully connected, except to collect statistics, and in an important special case, where the Asterisk instance is the endpoint itself.

An Asterisk instance can be an endpoint as the caller or the callee, but it is far more common for it to be the callee.

As the callee endpoint, Asterisk can provide a number of services to the caller endpoint, for example:

Asterisk configuration

Configuring Asterisk involves creating the contents ofa few (or many) files, usually at least:

Often Asterisk is used in these situations:

A home with a single PC and a single user on the same PC
In this case the main functionality is making and receiving calls and voicemail configured as an answering machine. There is not much need for menu systems, and no need for call transfers, parking or for internal sessions. Some people might want a very small hardware interface to a single PSTN line or to two ISDN ones, but almost everybody will be happy enough with incoming and outgoing PSTN calls to be done with remote provider.
A large home or a small office with one or more PCs running soft phones, and perhaps IP phones or analog-IP boxes
This probably requires internal sessions, and transfers, and probably parking is nice too, but menus are not that common. Usually an external PSTN gateway is acceptable, even if adding some hardware PSTN gateway may be desirable.
A medium to large office with very many PCs and phones, of all sorts, and multiple Asterisk server instances
This probably require extensive inter-Asterisk switching for internal calls, and the full panoply of advanced services, like voicemail call transfer, parking, menus. At least one of the Asterisk server has a hardware interface to PSTN services, via something like Digium Zapata cards or ISDN.

The configuration notes in this document are mostly about the small scale setups, with the following core assumptions:

Some other configuration will also be discussed in passing:

Preparations

Several things need to be prepared:

Asterisks needs to be installed
This is best done by using precompiled packages for you distribution.
A soft phone package needs to be select
Asterisk includes within itself a soft phone, usable in Asterisk command mode, but it is not pretty. Using a IAX2 phone like iaxComm may be best for comatibility, but a SIP phone like KPhone or LinPhone can do, and even an H.323 one like GnomeMeeting could be used, but H.323 is best forgotten.
Create a gateway account at IAXTel.com
This is very useful because it is a free way to test your setup and communicate with people who have a IAX2 soft phone. It gives a free virtual (no PSTN gateway) number with a prefix of +1 700.
Find one or two VoIP PSTN commercial gateways
A PSTN gateway gives you a PSTN phone number. Calls to this number are switched by the gateway to incoming external sessions to your Asterisk instance, and your asterisk instance can use the gateway to establish sessions via it to some PSTN phone number.
A gateway with a switch that supports IAX2 is best, but a SIP switch gateway is also usable, even if SIP is rather less efficient and has somewhat fewer features.
Sometimes a single gateway is good enough for both national and international calls, sometimes it is best to select two; sometimes one wants multiple international gateways in part because some providers may be cheaper for some countries than others, sometimes because one wants a local PSTN number for receiving calls in more than one country.
Some gateways charge for outgoing sessions, some charge instead incoming sessions, but to those that originate then, by giving their customers premium numbers.
There are also entirely free PSTN gateways that don't charge because they only gateway to free-of-charge PSTN numbers, but I think that is somewhat pointless.
Define the soft phones endpoint configurations
Define the commercial gateways switch configurations
Define a dialplan
This includes defining a session switching plan and adding services like voicemail, and perhaps more advanced ones like call transfer and parking.

We shall discuss below first the the setting up of a dial plan, then soft phone and gateway endpoints configuration.

The dialplan configuration

An Asterisk dialplan defines how a request to switch a session from an endpoint to another endpoint is handled.

This is done primarily by looking at the extension to be called, and classifying it into various classes, where all the extensions of the same class are switched similarly.

Sometimes the switching also depends on the characteristics of the caller (among the characteristics may be the extension, but usually the most important will be either the authenticated user name or the address), primarily to determine whether the caller is internal or external; as a rule external callers should not be able to have their sessions switched to external extensions, but only to internal ones.

Usually a dialplan contains these elements: