Asterisk - dual servers Chinese

Asterisk互連

概要


當然你可以使用 SIP 或 H.323 (but not MGCP) 來連接兩台 Asterisk servers, 然而 IAX 是較常見的方法 (Note: SIP > IAX > SIP does not currently work for video calls as of Jan 08). 為了共用 dialplan 你可以這樣做

  • 智慧的設計dialplan在每台server上, 這樣你就可從另一台server直接撥號。例: use 3xxx for server A, 4xxx for server B, and 5xxx for extensions on server C.
  • 使用 "switch" 陳述,可使server A 查找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

不同於 IAX , 在此檔內 sip.conf ,SIP 沒有明顯的區分 type=peer 和 type=user , 。你可一開始就在兩邊用 type=friend ,若能正常運作之後,你再開始考慮分別設定 peer 和 user。亦可參照sip.conf檔內的參數 "insecure=very" 和 "autocreatepeer=yes".

  • server A 為固定IP, server B 為動態 IP: 由 server B 去向 server A 註冊,將其寫在 sip.conf 檔
  • 兩邊都有固定 IP: 不需要註冊
  • 兩邊都為動態 IP: 這有些小麻煩, 你需要去 dyndns.org 像這樣的網站,去註冊兩個域名給兩台server用; in any case this is not a good setup as during IP change connectivity will be lost until the update has been propagated through dyndns.
  • 兩台Server 都在NAT後面: 別用 SIP, 改用 IAX2 吧。

IAX 設定細節

IAX 連接兩台Asterisk servers 設定步驟:

  • 兩邊都要設定此檔 iax.conf, 一個為 peer 另一個為 user.
  • 設定此帳號(user)的 dialplan 於 extensions.conf 內,這樣就可使此帳號(user)撥打到 peer.
  • Optionally, register the peer with the user (for when the peer's ip is dynamic and therefore unknown by the user.)
  • 重覆上述步驟,使用相對的設定設定在另一台(swap peer and user) 若你兩邊都想要可以撥打。


宣告 IAX2 使用者

當一台 peer 收到 calls 時,底下的資訊會需要寫在peer這台機器的 iax.conf 此檔內,才能做驗証帳號的動作。

[username]
type=user
auth=md5
secret=secretword
context=iax2users


這個 "context" 將來把來電的使用者(user)歸屬在你所指定的區段 (參閱 extensions.conf ).

此設定可讓遠方的使用者從任何一台機器註冊到你的系統裡。若你想要限制遠方使用者的IP或hostname的話,可加參數 permitdeny 在這台 peer機器的此檔內 iax.conf.



宣告IAX2 peer

user 要撥打電話時,底下的資訊會需要寫在user這台機器的 iax.conf 此檔內,以便於識別 (用於認證) 它自己的帳號,用以連接 peer 去撥打,而在 peer 接受這通呼叫之前會先鑑別身份。

[peername]
type=peer
host=hostname.domain.tld (or "dynamic" which would then require a "register" command by the peer.)
auth=md5
secret=secretword ; 備用,若它已崁入撥打字串內了
username=username-at-the-peer ; 備用,若它已崁入撥打字串內了



注意事項:
  • type=user 是用於認證進入的 call
  • type=peer 是你要撥打出去的節點
  • type=friend 上面兩個的綜合體

使用 type=friend 會簡單些, 但請當它是一種偷懶(不安全)的做法。 若你兩邊都設 type=friend 和 host=hostname 或域名等,則你可限制你的 peer 接受 call 的來源


這個參數的設定 auth=rsa 請參閱 Asterisk IAX RSA authentication wiki page.

現在我們已完成1,2的步驟了,只剩下設定 dialplan. 請參照底下的範例來完成它。


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.
注意:以上的設定帳號、密碼會顯示在 CDR 記錄裡 (你也許會想使用 example 2 或使用金鑰來取代帳號密碼)!

Example 2

此範例不會將帳號、密碼顯示在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.
exten => _7XXX,1,Dial(IAX2/username:pass@serverB/${EXTEN:1},30,r)


(serverA)
iax.conf
[general]
register => <username>:<password>@<serverB hostname or IP>

[serverB]
type=friend
user=<username>
secret=<password>
host=<serverB hostname or IP>

extensions.conf
exten => _7XXX,1,Dial(IAX2/serverB/${EXTEN:1},30,r)
exten => _7XXX,2,Congestion

(serverB)
iax.conf
[serverA]
type=friend
user=<username>
secret=<password>
host=<dynamic> | <serverA hostname or IP>

extensions.conf
exten => _8XXX,1,Dial(IAX2/serverA/${EXTEN:1},30,r)
exten => _8XXX,2,Congestion

在某些情況下 serverA and serverB, 會成為這台 server 的使用者帳號

Example 3

使用 Switch 項目,參閱 extensions.conf 你可以連接兩台Asterisk servers 和他的dial plan。在此例中"server C" 可連 "server A" 或 "server B":

[default]
exten => _801XXX,1,Goto,srvA|${EXTEN}|1
exten => _802XXX,1,Goto,srvB|${EXTEN}|1

[srvA]
exten => _801XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverA

[srvB]
exten => _802XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverB

Notes: 你可能未建立電路連結從 serverA 到 serverB and serverB 到 serverA! 請參閱 (新的) iax.conf 設定參數 "autokill=" 可避免當遠方的server當機或斷線時,發生long hang (咬線?掛不斷?) 的問題。

Example 4


In extensions.conf: (on slave)

[outbound]
switch => IAX2/master:secret@iax-gw1.company.net/outbound

In iax.conf (on master):

[slave]
type=user
auth=plaintext
context=outbound
context=outbound2 ; (can have multiple if you want)
secret=secret
host=dynamic
callerid="slave"
trunk=yes
notransfer=yes

[slave]
type=peer
auth=plaintext
context=outbound-nuphone
secret=secret
host=dynamic
trunk=yes
notransfer=yes

In extensions.conf (slave):

[assigned-dids]
; uncomment a dial mechanism, first one goes to specific extension
; other one goes to dial parameter s.

;exten => 7046446999,1,Dial,IAX2/master@slave/${EXTEN}
;exten => 7046446999,1,Dial,IAX2/master@slave

In iax.conf (slave):

register => slave:secret@iax-gw1.company.net

[master]
type=peer
host=iax-gw1.company.net
secret=secret
context=outbound
trunk=yes
canreinvite=no

[master]
type=user
secret=secret
context=acontext
trunk=yes
canreinvite=no



register 註冊指令

當 peer 的IP是未知的, user 無從撥打 (例: 當一位 office/user calls a teleworker/peer at home, where the teleworker has only a dynamic ip or is behind NAT.) To compensate for this, the teleworker/peer actively registers with the office/user by providing its identity and ip location.

On the peer, in the [general] section of iax.conf, add a registration entry:

register => user:password@hostname.domain.ext

The continually updates the user so it will always know how to reach the peer even if the peer's ip changes.

The "register" statement only works if you want to hook up a server with a dynamic IP to a server with a static (public) IP, i.e. on the user you must add "host=dynamic" in the iax.conf for that peer. If both servers are at known, static IPs then there is no need for a register statement as you'd use host=hostname on both ends.
--
Back to asterisk tips and tricks

Asterisk互連

概要


當然你可以使用 SIP 或 H.323 (but not MGCP) 來連接兩台 Asterisk servers, 然而 IAX 是較常見的方法 (Note: SIP > IAX > SIP does not currently work for video calls as of Jan 08). 為了共用 dialplan 你可以這樣做

  • 智慧的設計dialplan在每台server上, 這樣你就可從另一台server直接撥號。例: use 3xxx for server A, 4xxx for server B, and 5xxx for extensions on server C.
  • 使用 "switch" 陳述,可使server A 查找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

不同於 IAX , 在此檔內 sip.conf ,SIP 沒有明顯的區分 type=peer 和 type=user , 。你可一開始就在兩邊用 type=friend ,若能正常運作之後,你再開始考慮分別設定 peer 和 user。亦可參照sip.conf檔內的參數 "insecure=very" 和 "autocreatepeer=yes".

  • server A 為固定IP, server B 為動態 IP: 由 server B 去向 server A 註冊,將其寫在 sip.conf 檔
  • 兩邊都有固定 IP: 不需要註冊
  • 兩邊都為動態 IP: 這有些小麻煩, 你需要去 dyndns.org 像這樣的網站,去註冊兩個域名給兩台server用; in any case this is not a good setup as during IP change connectivity will be lost until the update has been propagated through dyndns.
  • 兩台Server 都在NAT後面: 別用 SIP, 改用 IAX2 吧。

IAX 設定細節

IAX 連接兩台Asterisk servers 設定步驟:

  • 兩邊都要設定此檔 iax.conf, 一個為 peer 另一個為 user.
  • 設定此帳號(user)的 dialplan 於 extensions.conf 內,這樣就可使此帳號(user)撥打到 peer.
  • Optionally, register the peer with the user (for when the peer's ip is dynamic and therefore unknown by the user.)
  • 重覆上述步驟,使用相對的設定設定在另一台(swap peer and user) 若你兩邊都想要可以撥打。


宣告 IAX2 使用者

當一台 peer 收到 calls 時,底下的資訊會需要寫在peer這台機器的 iax.conf 此檔內,才能做驗証帳號的動作。

[username]
type=user
auth=md5
secret=secretword
context=iax2users


這個 "context" 將來把來電的使用者(user)歸屬在你所指定的區段 (參閱 extensions.conf ).

此設定可讓遠方的使用者從任何一台機器註冊到你的系統裡。若你想要限制遠方使用者的IP或hostname的話,可加參數 permitdeny 在這台 peer機器的此檔內 iax.conf.



宣告IAX2 peer

user 要撥打電話時,底下的資訊會需要寫在user這台機器的 iax.conf 此檔內,以便於識別 (用於認證) 它自己的帳號,用以連接 peer 去撥打,而在 peer 接受這通呼叫之前會先鑑別身份。

[peername]
type=peer
host=hostname.domain.tld (or "dynamic" which would then require a "register" command by the peer.)
auth=md5
secret=secretword ; 備用,若它已崁入撥打字串內了
username=username-at-the-peer ; 備用,若它已崁入撥打字串內了



注意事項:
  • type=user 是用於認證進入的 call
  • type=peer 是你要撥打出去的節點
  • type=friend 上面兩個的綜合體

使用 type=friend 會簡單些, 但請當它是一種偷懶(不安全)的做法。 若你兩邊都設 type=friend 和 host=hostname 或域名等,則你可限制你的 peer 接受 call 的來源


這個參數的設定 auth=rsa 請參閱 Asterisk IAX RSA authentication wiki page.

現在我們已完成1,2的步驟了,只剩下設定 dialplan. 請參照底下的範例來完成它。


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.
注意:以上的設定帳號、密碼會顯示在 CDR 記錄裡 (你也許會想使用 example 2 或使用金鑰來取代帳號密碼)!

Example 2

此範例不會將帳號、密碼顯示在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.
exten => _7XXX,1,Dial(IAX2/username:pass@serverB/${EXTEN:1},30,r)


(serverA)
iax.conf
[general]
register => <username>:<password>@<serverB hostname or IP>

[serverB]
type=friend
user=<username>
secret=<password>
host=<serverB hostname or IP>

extensions.conf
exten => _7XXX,1,Dial(IAX2/serverB/${EXTEN:1},30,r)
exten => _7XXX,2,Congestion

(serverB)
iax.conf
[serverA]
type=friend
user=<username>
secret=<password>
host=<dynamic> | <serverA hostname or IP>

extensions.conf
exten => _8XXX,1,Dial(IAX2/serverA/${EXTEN:1},30,r)
exten => _8XXX,2,Congestion

在某些情況下 serverA and serverB, 會成為這台 server 的使用者帳號

Example 3

使用 Switch 項目,參閱 extensions.conf 你可以連接兩台Asterisk servers 和他的dial plan。在此例中"server C" 可連 "server A" 或 "server B":

[default]
exten => _801XXX,1,Goto,srvA|${EXTEN}|1
exten => _802XXX,1,Goto,srvB|${EXTEN}|1

[srvA]
exten => _801XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverA

[srvB]
exten => _802XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverB

Notes: 你可能未建立電路連結從 serverA 到 serverB and serverB 到 serverA! 請參閱 (新的) iax.conf 設定參數 "autokill=" 可避免當遠方的server當機或斷線時,發生long hang (咬線?掛不斷?) 的問題。

Example 4


In extensions.conf: (on slave)

[outbound]
switch => IAX2/master:secret@iax-gw1.company.net/outbound

In iax.conf (on master):

[slave]
type=user
auth=plaintext
context=outbound
context=outbound2 ; (can have multiple if you want)
secret=secret
host=dynamic
callerid="slave"
trunk=yes
notransfer=yes

[slave]
type=peer
auth=plaintext
context=outbound-nuphone
secret=secret
host=dynamic
trunk=yes
notransfer=yes

In extensions.conf (slave):

[assigned-dids]
; uncomment a dial mechanism, first one goes to specific extension
; other one goes to dial parameter s.

;exten => 7046446999,1,Dial,IAX2/master@slave/${EXTEN}
;exten => 7046446999,1,Dial,IAX2/master@slave

In iax.conf (slave):

register => slave:secret@iax-gw1.company.net

[master]
type=peer
host=iax-gw1.company.net
secret=secret
context=outbound
trunk=yes
canreinvite=no

[master]
type=user
secret=secret
context=acontext
trunk=yes
canreinvite=no



register 註冊指令

當 peer 的IP是未知的, user 無從撥打 (例: 當一位 office/user calls a teleworker/peer at home, where the teleworker has only a dynamic ip or is behind NAT.) To compensate for this, the teleworker/peer actively registers with the office/user by providing its identity and ip location.

On the peer, in the [general] section of iax.conf, add a registration entry:

register => user:password@hostname.domain.ext

The continually updates the user so it will always know how to reach the peer even if the peer's ip changes.

The "register" statement only works if you want to hook up a server with a dynamic IP to a server with a static (public) IP, i.e. on the user you must add "host=dynamic" in the iax.conf for that peer. If both servers are at known, static IPs then there is no need for a register statement as you'd use host=hostname on both ends.
--
Back to asterisk tips and tricks
Created by: dominic16y, Last modification: Fri 15 of Mar, 2013 (03:16 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+