Peering two Asterisk servers using IAX

From Etel

Jump to: navigation, search

Contents

Peering two Asterisk servers using IAX

Problem

You want to connect together two Asterisk servers so that the dialplan on one server can call extensions on the other server.

Solution

We imagine that we have two Asterisk boxes, called foo and bar. foo is at 192.168.1.2 while bar is at 192.168.2.3. Le's start with foo; here is its iax.conf file:

[general]
bindport = 4569           
bindaddr = 0.0.0.0  
disallow=all
allow=ulaw
allow=alaw
allow=gsm
mailboxdetail=yes

[bar]
type=friend
username=foo
secret=password123
auth=plaintext
host=192.168.2.3
context=fromiax
peercontext=fromiax
qualify=yes
trunk=yes

This configuration means that on foo we can execute the command Dial(iax2/bar/23) and this will call extension 23 at context fromiax on bar.

Now we build a very similar configuration for the other server, bar:

[general]
bindport = 4569 
bindaddr = 0.0.0.0  
disallow=all
allow=ulaw
allow=alaw
allow=gsm
mailboxdetail=yes

[foo]
type=friend
username=bar
secret=password123
auth=plaintext
host=192.168.1.2
context=fromiax
peercontext=fromiax
qualify=yes
trunk=yes

As you can see, we made specular changes in the section name and username and host, while keeping the same password.

Of course, on both servers we have to create a context named fromiax in extensions.conf that acts as a 'landing zone' for incoming calls from the other server.

Now on foo we can Dial(iax2/bar/23) to reach extension 23@fromiax on bar, and on bar we can dial Dial(iax2/foo/42) to reach extension 42@fromiax on foo.

Discussion

To make this recipe work, we are basically setting up the two servers to share a connection that uses the same password on both ends. This makes it very easy to configure the connection as a single entity and not two separate incoming and outgoing sections for each server.

The meaning of the various entries on the foo server is examined; specular entries are present on bar.

We use bar as the name of the section so we can Dial(iax2/bar) and we add login and password so we don't need to set them manually in the dialplan.

We define the type as friend, meaning that we will both send and receive calls to bar. This is the same as defining both user and peer sections, but does save time and visual complexity when editing the file.

The username is the name of the iax.conf section on bar where we will look for IAX peering information; the secret is the connection password. Use the same password for both sides of the peering, if you are using type friend. The auth line details kind of authentication performed; you may want to use safer methods that sending plaintext passwords as in this case, like setting it to md5.

The host is the IP address of the server bar. As we specify IP addresses, we have no need for a reciprocal server registration.

The context is the context in which we will accept the extension bar will be sending foo when it tries to place a call. We can have more than one possible context line for bar, so they can choose in which of the allowed contexts they want to call us.

The peercontext is used to avoid typing in the context in the Dial() command, so that we can write the easier dial string iax2/bar/23 instead of iax2/bar/23@fromiax.

The qualify option generates a kind of 'pings' between the servers, so they make sure the other part is ready and makes round-time statistics available from the Asterisk CLI interface.

The trunk option makes sure that if more than one call is travelling between the servers, they will be sent in a way that saves quite a bit of IP overhead.

See Also:

?

Metadata

Personal tools