Asterisk+GOIP 将SIM卡转为SIP

版权声明

起因:
在几年前我买了个北京铁通商务通的无线座机,类似于小灵通,必须处于北京移动覆盖范围内才可以使用。但是最近几年不在北京租房子了,出了北京就没有信号。
所以,我想找个朋友,把机器扔到朋友家,可是也不能老麻烦人家帮忙接电话啊。。。所以,我在想有啥办法能把SIM卡转成VOIP,只要机器放在北京,插上电就不用管了,登陆VOIP账号就能在任何地点接打电话。

之后我就看到有个硬件设备叫做GOIP,可以把SIM卡转为VOIP客户端。

当然,我也看到了其他人树莓派+USB卡托的教程(https://steemit.com/cn/@ety001/5zehat),但是我觉得还是买现成的设备比较稳定。

我主要参考了以下文章:
https://joybean.org/2018/05/30/iphone-multi-card-multi-standby-schema-solution-voip-and-goip
https://github.com/tangaza/Tangaza/wiki/Connecting-a-GoIP-GSM-VoIP-gateway-to-an-Asterisk-AGI

我的Asterisk采用VPS,系统是Ubuntu 18.04,Asterisk直接apt install安装好。
安装好后只需要修改两个文件。配置文件的具体变量可以参考:
https://github.com/asterisk/asterisk/blob/master/configs/samples/sip.conf.sample
https://github.com/asterisk/asterisk/blob/master/configs/samples/extensions.conf.sample
https://www.cnblogs.com/Loadhao/p/6835331.html
https://blog.csdn.net/u013132673/article/details/52571371
https://jyqc688.iteye.com/blog/2277289
https://www.cnblogs.com/lr393993507/p/5309913.html
https://www.voip-info.org/asterisk-config-sipconf/
https://www.voip-info.org/asterisk-config-extensionsconf/

/etc/asterisk/sip.conf
在general修改以下内容:
增加:
bindport=5060
bindaddr=0.0.0.0
修改:
context=default
tcpenable=yes
allowoverlap=yes ;用于支持接通后输入卡号密码之类的。

allowguest=yes
dtmfmode=rfc2833
videosupport=yes
disallow=all
allow=ulaw
allow=alaw
allow=g729
allow=h263
allow=h263p
allow=h264
allow=gsm
qualify=yes

在文件末尾增加以下内容
[goip] ;goip设备账户参数,请自行设定password
canreinvite=no
context=incoming
dtmfmode=rfc2833
fromuser=goip
host=dynamic
disallow=all
allow=ulaw
allow=alaw
allow=g729
insecure=port,invite
secret=password
defaultname=goip
nat=yes ;设备如果在防火墙或者其他设备后面需要增加nat=yes。
qualify=yes
type=friend
[username];用户账户参数,请自行设定user和password
type=friend
context=outcoming
callerid = user
secret = password
host = dynamic
canreinvite = no
dtmfmode = rfc2833
mailbox = user
disallow = all
allow = ulaw
transport = udp
qualify=yes
nat=yes

/etc/asterisk/extensions.conf
在general部分后增加以下内容:

[incoming] ;我这个案例。。。是闲的蛋疼做了个语音菜单,哈哈哈~
exten => 6666,1,Answer() ;6666是GoIP>配置>呼入管理>转移号码中填写的数字,VOIP服务器监听6666这个号码进行应答。
exten => 6666,2,Wait(3)
exten => 6666,3,Playback(/var/lib/asterisk/sounds/1) ;录音文件必须是gsm格式,要提前放在/var/lib/asterisk/sounds/,把文件chown改成asterisk:asterisk
exten => 6666,4,Playback(/var/lib/asterisk/sounds/2)
exten => 6666,5,Dial(SIP/USER,30,r) ;USER填写你上面sip.conf设定的用户名,呼叫30秒若无应答放弃接通,r作为第3个参量,在通知被叫通道有来电的这段时间内,主叫方会听到振铃声音。
exten => 6666,6,Hangup()

[outcoming]
exten => _0.,1,Dial(SIP/${EXTEN:1}@goip,30,r);拨出号码前加0可以通过goip呼出,例如010010,就是呼叫10010,例如0+85212345678,就是呼叫国际区号为+852号码为12345678。
exten => goip,1,Dial(SIP/goip,30,r)
exten => nby,1,Dial(SIP/USER,30,r)

[default]
exten => goip,1,Answer()
exten => goip,n,Dial(SIP/goip,30,r)
exten => goip,n,Hangup
exten => USER,1,Answer()
exten => USER,n,Dial(SIP/USER,30,r)
exten => USER,n,Hangup

除此之外,记得fail2ban也要增加Asterisk的防护规则:
http://www.fail2ban.org/wiki/index.php/Asterisk
https://cyphercodes.github.io/2018/04/08/Secure-Asterisk-13-with-Fail2ban-on-Ubuntu-16-04/

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *