Asterisk配置iax服务器

做一个最基本的SIP以及IAX之间互相正常通信的测试。这对Asterisk的工作以及通信流程的了解相当有帮助。


一.配置Asterisk相关文件:
这里的配置我只是列出自己的定制部分,其他部分就不贴出来了。
1.IAX配置文件
[root@asterisk-test1 ~]# vi /etc/asterisk/iax.conf
-------------------------------------------------------------------------------------
[iax](!)
type=friend
context=test
disallow=all
allow=gsm
qualify=yes
host=dynamic
transfer=no
auth=md5



[8801](iax)
username=8801
secret=123456
context=test



[8802](iax)
username=8802
secret=123456
context=test
-------------------------------------------------------------------------------------




2.SIP配置文件
[root@asterisk-test1 ~]# vi /etc/asterisk/sip.conf
-------------------------------------------------------------------------------------
[sip](!)
type=friend
host=dynamic
disallow=all
allow=gsm
context=test



[9901](sip)
username=9901
secret=123456



[9902](sip)
username=9902
secrest=123456
-------------------------------------------------------------------------------------




3.配置拨号方案
[root@asterisk-test1 ~]# vi /etc/asterisk/extensions.conf
-------------------------------------------------------------------------------------
[test]
exten => _880X,1,Dial(IAX2/${EXTEN},,r)
exten => _990X,1,Dial(SIP/${EXTEN},,r)
-------------------------------------------------------------------------------------





二.进入控制台调试:
[root@asterisk-test1 asterisk]# asterisk -crvvv
-------------------------------------------------------------------------------------
Asterisk 1.4.5, Copyright (C) 1999 - 2007 Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
== Parsing '/etc/asterisk/asterisk.conf': Found
== Parsing '/etc/asterisk/extconfig.conf': Found
Connected to Asterisk 1.4.5 currently running on asterisk-test1 (pid = 19690)
Verbosity is at least 47
Core debug is at least 255



调整Debug级别
asterisk-test1*CLI> core set debug 255
Core debug is at least 255



重新载入IAX配置
asterisk-test1*CLI> iax2 reload
== Parsing '/etc/asterisk/iax.conf': Found
== Parsing '/etc/asterisk/users.conf': Found
== Loaded firmware 'iaxy.bin'
== Parsing '/etc/asterisk/iaxprov.conf': Found
-- Loaded provisioning template 'default'



重新载入SIP配置
asterisk-test1*CLI> sip reload
Reloading SIP*CLI>
== Parsing '/etc/asterisk/sip.conf': Found
== Parsing '/etc/asterisk/users.conf': Found
== Parsing '/etc/asterisk/sip_notify.conf': Found



重新载入拨号规则配置
asterisk-test1*CLI> extensions reload
== Parsing '/etc/asterisk/extensions.conf': Found
== Setting global variable 'CONSOLE' to 'Console/dsp'
== Setting global variable 'IAXINFO' to 'guest'
== Setting global variable 'TRUNK' to 'Zap/g2'
== Setting global variable 'TRUNKMSD' to '1'
-- Registered extension context 'test'
-- Added extension '_880X' priority 1 to test
-- Added extension '_990X' priority 1 to test
-------------------------------------------------------------------------------------





三.注册终端:
-------------------------------------------------------------------------------------
注册SIP终端9901
-- Registered SIP '9901' at 192.168.0.199 port 37624 expires 60
-- Saved useragent "eyeBeam release 1004p stamp 31962" for peer 9901
[Nov 5 14:47:33] NOTICE[19715]: chan_sip.c:12231 handle_response_peerpoke: Peer '9901' is now Reachable. (5ms / 2000ms)



这册SIP终端9902
-- Registered SIP '9902' at 192.168.0.149 port 23260 expires 3600
-- Saved useragent "eyeBeam release 1004p stamp 31962" for peer 9902
[Nov 5 14:48:21] NOTICE[19715]: chan_sip.c:12231 handle_response_peerpoke: Peer '9902' is now Reachable. (7ms / 2000ms)



注册IAX终端8801  (测试iax协议的终端可以去 http://www.zoiper.com/softphone/ 下载)
-- Registered IAX2 '8801' (AUTHENTICATED) at 192.168.0.199:4569
[Nov 5 15:06:32] NOTICE[19708]: chan_iax2.c:5699 update_registry: Restricting registration for peer '8801' to 60 seconds (requested 300)



注册IAX终端8802
-- Registered IAX2 '8802' (AUTHENTICATED) at 192.168.0.149:4569
[Nov 5 15:07:41] NOTICE[19707]: chan_iax2.c:5699 update_registry: Restricting registration for peer '8802' to 60 seconds (requested 300)
-------------------------------------------------------------------------------------





四.测试IAX之间呼叫:
1.IAX被叫方挂断
-------------------------------------------------------------------------------------
-- Accepting AUTHENTICATED call from 192.168.0.199:
接受经过验证的呼叫,接受8801呼叫8802。



> requested format = gsm,
> requested prefs = (),
> actual format = gsm,
> host prefs = (gsm),
> priority = mine
-- Executing [8802@test:1] Dial("IAX2/8801-4", "IAX2/8802||r") in new stack
执行8801通道4向8802进行呼叫。



-- Called 8802>
-- Call accepted by 192.168.0.149 (format gsm)
-- Format for call is gsm
协商编解码为GSM。



-- IAX2/8802-5 is ringing
被叫方8802通道5产生振铃。

-- IAX2/8802-5 answered IAX2/8801-4
被叫方8802通道5应答了主叫方8801通道4。



...通话...



-- Hungup 'IAX2/8802-5'
被叫方8802通道5首先挂断。



== Spawn extension (test, 8802, 1) exited non-zero on 'IAX2/8801-4'
-- Hungup 'IAX2/8801-4'
主叫方8801通道4之后断开。
-------------------------------------------------------------------------------------




2.IAX主叫方挂断
-------------------------------------------------------------------------------------
-- Accepting AUTHENTICATED call from 192.168.0.149:
接受经过验证的呼叫,结合8802呼叫8801。



> requested format = gsm,
> requested prefs = (),
> actual format = gsm,
> host prefs = (gsm),
> priority = mine
-- Executing [8801@test:1] Dial("IAX2/8802-2", "IAX2/8801||r") in new stack
执行8802通道2向8802进行呼叫。



-- Called 8801>
-- Call accepted by 192.168.0.199 (format gsm)
-- Format for call is gsm
协商编码呼叫为GSM。



-- IAX2/8801-5 is ringing
被叫方8801通道5进行振铃。



-- IAX2/8801-5 answered IAX2/8802-2
被叫方8801通道5应答了主叫方8802通道2。



...通话...



-- Hungup 'IAX2/8802-2'
主叫方8802通道2首先挂断。



== Spawn extension (test, 8801, 1) exited non-zero on 'IAX2/8801-5'
-- Hungup 'IAX2/8801-5'
被叫方8801通道5之后断开。
-------------------------------------------------------------------------------------





五.测试SIP 之间呼叫:
1.主叫方挂断
-------------------------------------------------------------------------------------
-- Executing [9902@test:1] Dial("SIP/9901-0854e7c8", "SIP/9902||r") in new stack
执行9901呼叫9902。



-- Called 9902>
-- SIP/9902-08552730 is ringing
被叫方9902振铃。



Internal RTCP NTP clock skew detected: lsr=1110524996, now=1174799434, dlsr=809841730 (12357:204ms), diff=745567292
-- SIP/9902-08552730 answered SIP/9901-0854e7c8
被叫方9902应答了主叫方9901。



-- Native bridging SIP/9901-0854e7c8 and SIP/9902-08552730
Internal RTCP NTP clock skew detected: lsr=1127362869, now=1174802408, dlsr=808530993 (12337:203ms), diff=761091454
建立连接,开始通话。

== Spawn extension (test, 9902, 1) exited non-zero on 'SIP/9901-0854e7c8'
主叫方9901挂断。
-------------------------------------------------------------------------------------




2.被叫方挂断
-------------------------------------------------------------------------------------
-- Executing [9902@test:1] Dial("SIP/9901-08549ad8", "SIP/9902||r") in new stack
执行9901呼叫9902。



-- Called 9902>
-- SIP/9902-0854fc30 is ringing
被叫方9902振铃。



Internal RTCP NTP clock skew detected: lsr=1110524996, now=1183429154, dlsr=809841730 (12357:204ms), diff=736937572
-- SIP/9902-0854fc30 answered SIP/9901-08549ad8
被叫方9902应答主叫方9901。



-- Native bridging SIP/9901-08549ad8 and SIP/9902-0854fc30
Internal RTCP NTP clock skew detected: lsr=1127362869, now=1183429827, dlsr=808530993 (12337:203ms), diff=752464035
建立连接,开始通话。



== Spawn extension (test, 9902, 1) exited non-zero on 'SIP/9901-08549ad8'
被叫方9902挂断。
-------------------------------------------------------------------------------------





六.测试IAX主叫SIP:
1.主叫方挂断
-------------------------------------------------------------------------------------
-- Accepting AUTHENTICATED call from 192.168.0.199:
接受经过验证的呼叫,8801呼叫9901。



> requested format = gsm,
> requested prefs = (),
> actual format = gsm,
> host prefs = (gsm),
> priority = mine
-- Executing [9901@test:1] Dial("IAX2/8801-2", "SIP/9901||r") in new stack
执行8801通道2呼叫9901。



-- Called 9901>
-- SIP/9901-0854e7c8 is ringing
被叫方9901振铃。



Internal RTCP NTP clock skew detected: lsr=1127362869, now=1141816690, dlsr=808530993 (12337:203ms), diff=794077172
-- SIP/9901-0854e7c8 answered IAX2/8801-2
被叫方9901应答主叫方8801通道2,建立连接,开始通话。



Internal RTCP NTP clock skew detected: lsr=1142150038, now=1142224038, dlsr=102498 (1:563ms), diff=28498
Internal RTCP NTP clock skew detected: lsr=1142150038, now=1142423096, dlsr=302972 (4:622ms), diff=29914
Internal RTCP NTP clock skew detected: lsr=1142477782, now=1142604149, dlsr=149422 (2:279ms), diff=23055
Internal RTCP NTP clock skew detected: lsr=1142477782, now=1142741562, dlsr=349962 (5:339ms), diff=86182
Internal RTCP NTP clock skew detected: lsr=1142805424, now=1142875129, dlsr=103874 (1:584ms), diff=34169
Internal RTCP NTP clock skew detected: lsr=1142805424, now=1143037482, dlsr=304414 (4:644ms), diff=72356
通话中。



== Spawn extension (test, 9901, 1) exited non-zero on 'IAX2/8801-2'
-- Hungup 'IAX2/8801-2'
主叫方8801通道2挂断。
-------------------------------------------------------------------------------------




2.被叫方挂断
-------------------------------------------------------------------------------------
-- Accepting AUTHENTICATED call from 192.168.0.199:
接受经过验证的呼叫,8801呼叫9901。



> requested format = gsm,
> requested prefs = (),
> actual format = gsm,
> host prefs = (gsm),
> priority = mine
-- Executing [9901@test:1] Dial("IAX2/8801-1", "SIP/9901||r") in new stack
执行8801通道2呼叫9901。



-- Called 9901>
-- SIP/9901-0854d248 is ringing
被叫方9901振铃。



Internal RTCP NTP clock skew detected: lsr=1127362869, now=1154364407, dlsr=808530993 (12337:203ms), diff=781529455
-- SIP/9901-0854d248 answered IAX2/8801-1
被叫方9901应答主叫方8801通道1。建立连接,开始通话。



Internal RTCP NTP clock skew detected: lsr=1155023403, now=1155058464, dlsr=52756 (0:804ms), diff=17695
Internal RTCP NTP clock skew detected: lsr=1155023403, now=1155203176, dlsr=277217 (4:229ms), diff=97444
Internal RTCP NTP clock skew detected: lsr=1155351087, now=1155366776, dlsr=18415 (0:280ms), diff=2726
Internal RTCP NTP clock skew detected: lsr=1155678855, now=1155767542, dlsr=127074 (1:938ms), diff=38387
Internal RTCP NTP clock skew detected: lsr=1155678855, now=1155914097, dlsr=351469 (5:362ms), diff=116227
通话中。



== Spawn extension (test, 9901, 1) exited non-zero on 'IAX2/8801-1'
-- Hungup 'IAX2/8801-1'
被叫方9901挂断。
-------------------------------------------------------------------------------------





七.测试SIP主叫IAX:
1.主叫方挂断
-------------------------------------------------------------------------------------
-- Executing [8801@test:1] Dial("SIP/9901-08549ad8", "IAX2/8801||r") in new stack
-- Called 8801
-- Call accepted by 192.168.0.199 (format gsm)
-- Format for call is gsm
-- IAX2/8801-1 is ringing

-- IAX2/8801-1 answered SIP/9901-08549ad8

Internal RTCP NTP clock skew detected: lsr=1127362869, now=1160125691, dlsr=808530993 (12337:203ms), diff=775768171
Internal RTCP NTP clock skew detected: lsr=1160782332, now=1160838023, dlsr=81526 (1:243ms), diff=25835
Internal RTCP NTP clock skew detected: lsr=1160782332, now=1160972114, dlsr=308281 (4:703ms), diff=118499
Internal RTCP NTP clock skew detected: lsr=1161109974, now=1161122977, dlsr=16973 (0:258ms), diff=3970
Internal RTCP NTP clock skew detected: lsr=1161109974, now=1161337308, dlsr=243662 (3:717ms), diff=16328


-- Hungup 'IAX2/8801-1'
== Spawn extension (test, 8801, 1) exited non-zero on 'SIP/9901-08549ad8'
-------------------------------------------------------------------------------------




2.被叫方挂断
-------------------------------------------------------------------------------------
-- Executing [8801@test:1] Dial("SIP/9901-0854e7c8", "IAX2/8801||r") in new stack
-- Called 8801>
-- Call accepted by 192.168.0.199 (format gsm)
-- Format for call is gsm
-- IAX2/8801-2 is ringing

-- IAX2/8801-2 answered SIP/9901-0854e7c8

Internal RTCP NTP clock skew detected: lsr=1127362869, now=1167447869, dlsr=808530993 (12337:203ms), diff=768445993
Internal RTCP NTP clock skew detected: lsr=1168103692, now=1168159910, dlsr=86245 (1:315ms), diff=30027
Internal RTCP NTP clock skew detected: lsr=1168103692, now=1168307381, dlsr=312344 (4:765ms), diff=108655
Internal RTCP NTP clock skew detected: lsr=1168431378, now=1168476183, dlsr=52559 (0:801ms), diff=7754
Internal RTCP NTP clock skew detected: lsr=1168431378, now=1168707218, dlsr=278593 (4:250ms), diff=2753

-- Hungup 'IAX2/8801-2'
== Spawn extension (test, 8801, 1) exited non-zero on 'SIP/9901-0854e7c8'
-------------------------------------------------------------------------------------



基本上IAX与SIP之间可以最基本地互相通信了。

本文转自http://blog.csdn.net/net_flyfox/article/details/4126674

有些小的修改

如有疑惑可以留言

原文地址:https://www.cnblogs.com/yhyjy/p/2607809.html