如何连接两台Asterisk服务器

本文详细介绍了如何使用IAX协议连接两台Asterisk服务器,包括配置iax.conf、sip.conf和extensions.conf文件,以及处理动态IP、NAT等场景。通过设置互为用户和对等体,实现双向通话,并提供了多种示例配置,帮助读者成功建立Asterisk服务器之间的连接。
摘要由CSDN通过智能技术生成
 

Connecting two Asterisk servers

Overview


Of course you can also use SIP or H.323 (but not MGCP) to interlink two Asterisk servers, however IAX is the most common approach. In order to share a dialplan you can

  • intelligently design the dialplan on each server so that it becomes immediately clear when an extension on the other server is dialed, e.g. use 3xxx for server A, 4xxx for server B, and 5xxx for extensions on server C.
  • use the "switch" statement to make server A lookup locally unkown extensions on server B (both boxes must be permanently on-line, if that is not the case you'll experience large delays when dialing!)
  • use DUNDi: Distributed Universal Number Directory (DUNDi)
  • use EnumLookup (e.164)

SIP methods

Unlike with IAX there is no clean distinction between type=peer and type=user when it comes to sip.conf. You can start out with type=friend on both sides, and if you get that working you'll probably want to split the entry into a peer and a user. Also take a look at the sip.conf parameters "insecure=very" and maybe "autocreatepeer=yes".

  • server A with static IP, server B with dynamic IP: Register server B with server A in sip.conf
  • both servers with static IP: No need to register at all
  • both servers with dynamic IP: That's a bit tricky, you'll need to resort to a service like dyndns.org in to be able to register the servers with each other; in any case this is not a good setup as during IP change connectivity will be lost until the update has been propagted thru dyndns.
  • both servers behind their own NAT: Don't use SIP, turn to IAX2 instead

 

IAX setup details

An IAX connection between two Asterisk servers is setup in steps:

  • Configure Asterisk servers at both ends in iax.conf, one as peer and the other as user.
  • Set up the user's dialplan in extensions.conf so that calls can be made from the user to the peer.
  • Optionally, register the peer with the user (for when the peer's ip is dynamic and therefore unknown by the user.)
  • Repeat the previous steps in the opposite direction (swap peer and user) if you want to be able to place calls in both directions.

Declaration of IAX2 user

A peer receives calls. The following would be needed in iax.conf on the peer machine to verify (authenticate) the identify of the user before allowing calls from that user.

[username]
 type=user

 auth=md5
 secret=secretword
 context=iax2users

The "context" is important as it sets the local context in which to place any calls incoming from this user (see extensions.conf ).

This setup lets the remote user register to your system from any host. If you want to restrict which IP-address or hostname the remote user connects from, add permit or deny settings when describing the user in the peer's iax.conf.
Declaration of IAX2 peer

A user makes calls. The following would be needed in iax.conf on the user machine to identify (authenticate) itself to the peer before the peer will take the call.

[peername]
 type=peer

 host=hostname.domain.tld (or "dynamic" which would then require a "register" command by the peer.)
 auth=md5
 secret=secretword                  ; redundant when already embedded in Dial string
 username=username-at-the-peer       ; redundant when already embedded in Dial string

 


Please note:

·       a type=user is to authenticate an incoming call

·       a type=peer is someone you send a call to

·       type=friend, of course, is both


Using type=friend makes life easier, but treat it as a shortcut. If you add both type=friend and host=hostname, domain.ext you limit the hosts your peer can place calls from, which may not be what you want.

For instructions on using auth=rsa, see Asterisk IAX RSA authentication wiki page.
Now that we have completed steps 1 and 2 the only thing left is to set up the dialplan. Read the examples below for how to acomplish that.
Connecting the dial plans

Example 1

extensions.conf:
 exten => _7XXX,1,Dial(IAX2/myserver:passwordA@IAXserverA/${EXTEN:1},30,r)

 exten => _7XXX,2,Dial(SIP/myserver:passwordA@SIPserverA/${EXTEN:1},30,r)
 exten => _7XXX,3,Congestion

 exten => _8XXX,1,Dial(IAX2/myserver:passwordB@IAXserverB/${EXTEN:1},30,r)
 exten => _8XXX,2,Dial(SIP/myserver:passwordB@SIPserverB/${EXTEN:1},30,r)
 exten => _8XXX,3,Congestion
Of course we'll need matching entries like [IAXserverA] etc. in iax.conf and sip.conf in order for the above to work as intended. The example uses SIP as a fallback in case we have problems with your IAX connection.
Note that with this approach username and password will be shown in the CDR records (you might want to use the second example or to look at using keys instead of a username/password combination)!

Example 2

This example doesn't show the username and secret in the CDR.

Note: As if 1.0.9 this shortcut is still not part of the Asterisk Stable branch, so still requires the user and password as part of the dial string in extensions.conf. e.g.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值