DN42 asterisk PBX Peering

想在拖拉机网络上和别的小可爱互通电话吗~

安装 asterisk

(方法1) 使用debian buster:

apt install --install-recommends asterisk

(方法2) 使用docker

FROM debian:buster

RUN apt update -qq && \
    DEBIAN_FRONTEND=noninteractive apt -o Dpkg::Options::=--force-confold install -y --install-recommends asterisk asterisk-mp3 && \
    apt clean && rm -rf /var/lib/apt/lists/*

VOLUME ["/etc/asterisk", "/var/lib/asterisk", "/var/log/asterisk"]
WORKDIR /var/lib/asterisk
CMD ["/usr/sbin/asterisk", "-fp", "-U", "asterisk"]

或者…

docker pull isjerryxiao/asterisk

有了image之后 run的时候不要忘记创建三个命名卷保存pbx的数据

docker run -d --restart always \
    --mount "type=volume,dst=/etc/asterisk,src=asterisk1" \
    --mount "type=volume,dst=/var/lib/asterisk,src=asterisk2" \
    --mount "type=volume,dst=/var/log/asterisk,src=asterisk3" \
    isjerryxiao/asterisk

*可选部分: 创建一个docker network分一段 /30 和 /126 专门给pbx用 或者直接使用host network,以避免端口转发

docker network create --subnet 172.21.80.84/30 --gateway 172.21.80.87 \
    --ipv6 --subnet fd07:d34:7969:2f::/126 --gateway fd07:d34:7969:2f::2 pbxnet
docker run --network pbxnet {...}

配置 asterisk

(1) 配置sip

编辑 /etc/asterisk/sip.conf

[general]
context=context1
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
transport=udp                   ; Set the default transports.  The order determines the primary default transport.
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls

[mydevice1]
type=peer
secret=abcdef
host=dynamic
context=context1

[mydevice2]
type=peer
secret=123456
host=dynamic
context=context1

[mydn42peer1]
type=peer
host=172.2x.xxx.xxx
; port=5060
; port=5160
insecure=port,invite
context=context1

[mydn42peer2]
type=peer
host=172.2x.xxx.xxx
; port=5060
; port=5160
insecure=port,invite
context=context1

动态(dynamic)的sip客户端根据连接时提供的用户名(就是上面的mydeivce1/2)与密码来相互区分。自己的sip客户端(手机等设备)和将要peer的pbx类型都是peer哦。

(2) 配置dialplan

配好了sip,这时候还不能打电话哦。我们要告诉pbx号码和sip peer的映射关系。dialplan的更多强大功能在此就不过多介绍了(咱也一知半解),请自行查阅手册。

打开 /etc/asterisk/extensions.conf 进行编辑

[general]
static=yes
writeprotect=no
clearglobalvars=no

[mydialplan]
exten => _X./mydevice1,1,Set(CALLERID(number)=424036180001)
exten => _X./mydevice2,1,Set(CALLERID(number)=424036180002)
exten => _X.,1,NoOp()

exten => _XXXX,2,Goto(42403618${EXTEN},1)
exten => _XXXXXXXX,2,Goto(4240${EXTEN},1)
exten => _XXXXXXXXX,2,Goto(424${EXTEN},1)
exten => _X.,2,NoOp()

exten => _42403618XXXX,3,Answer()

exten => 424036180000,4,Playback(silence/1&hello-world&silence/1)

exten => 424036180001,4,Dial(SIP/mydevice1)
exten => 424036180002,4,Dial(SIP/mydevice2)

exten => 424036183618,4,Playback(silence/1&your&number&is)
exten => 424036183618,5,SayAlpha(${CALLERID(num)})
exten => 424036183618,6,Playback(silence/1)

exten => _42403618XXXX,5,Playback(im-sorry&check-number-dial-again)

exten => _42401234XXXX,4,Set(CALLERID(name)=jerryxiao)
exten => _42401234XXXX,5,Dial(SIP/mydn42peer1/${EXTEN:-4})

exten => _42401235XXXX,4,Set(CALLERID(name)=jerryxiao)
exten => _42401235XXXX,5,Dial(SIP/mydn42peer2/${EXTEN})

其中

exten => _X./mydevice1,1,Set(CALLERID(number)=424036180001)
exten => _X./mydevice2,1,Set(CALLERID(number)=424036180002)
exten => _X.,1,NoOp()

设置了callerid(呼出号码),也就是别人看到的来电号码。

exten => _XXXX,2,Goto(42403618${EXTEN},1)
exten => _XXXXXXXX,2,Goto(4240${EXTEN},1)
exten => _XXXXXXXXX,2,Goto(424${EXTEN},1)
exten => _X.,2,NoOp()

将号码补全区号(0+DN42的asn后四位),和国家号(DN42钦定424),支持的补全:0001, 36180001, 036180001 -> 424036180001

exten => 424036180000,4,Playback(silence/1&hello-world&silence/1)

设定呼叫424036180000的行为: 无声等待一秒,播放hello-world,无声等待一秒

exten => 424036180001,4,Dial(SIP/mydevice1)

设定呼叫424036180001的行为: 呼叫sip的对等方

exten => 424036183618,4,Playback(silence/1&your&number&is)
exten => 424036183618,5,SayAlpha(${CALLERID(num)})
exten => 424036183618,6,Playback(silence/1)

设定呼叫424036183618的行为: 读出对方的号码

exten => _42403618XXXX,5,Playback(im-sorry&check-number-dial-again)

处理剩下的号码: 告诉呼叫方号码不存在

exten => _42401234XXXX,4,Set(CALLERID(name)=jerryxiao)
exten => _42401234XXXX,5,Dial(SIP/mydn42peer1/${EXTEN:-4})

exten => _42401235XXXX,4,Set(CALLERID(name)=jerryxiao)
exten => _42401235XXXX,5,Dial(SIP/mydn42peer2/${EXTEN})

处理去往pbx peer的号码: 这部分根据peer的配置不同有所不同。如${EXTEN:-4}提取号码的最后4位并且使用这4位号码呼叫peer。如果使用的是上述配置,那么peer应该可以接受${EXTEN:-4}和${EXTEN}中任何一种配置。

至此基本配置就完成了,可以reload整个asterisk (asterisk -r 并执行reload),然后可以在手机上配置sip,或者寻找一个sip软件(如jami-gnome)互相拨打电话哦。

与我peer

我的pbx实例位于 pbx.jerry.dn42 / pbx.jerry.neo

号码段 42403618XXXX

更多

参阅文档,也可以在下方留言帮助完善本页面。

https://wiki.asterisk.org/wiki/display/AST/Dialplan

5 1 vote
Article Rating
Published
Categorized as Posts
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments