SIP代理如何解决NAT相关的问题

本文介绍了如何使用opensips作为SIP代理服务器,解决内网与外网话机在NAT环境下的注册和通信问题。方案中,opensips仅处理信令消息代理,配合rtpproxy处理媒体流。关键步骤包括检测NAT,维护nat table,以及利用Path和Route确保INVITE请求经过代理,实现内外网通信。
摘要由CSDN通过智能技术生成

背景

公司打算把freeswitch部署在本地局域网中,让后希望内网的话机以及外网的话机可以注册到该freeswitch上。(目前SBC的概念已经被好多人给乱用了,原本SBC强调的session的边界控制,但现在这些人又分了个i-SBC、a-SBC,后者完全跟SBC不沾边)

方案

经过调研,计划在公网上部署一台proxy服务器,负责sip信令以及媒体流的代理。其中SIP代理选择的是opensips,媒体代理选择的是rtpproxy。本文只展示opensips的配置脚本

网上的方案,基本都是将opensips作为注册服务器,而我的方案中opensips只负责信令消息的代理。

依赖的模块

  1. path:用来支持Path扩展,在呼叫经过该代理注册到freeswitch的话机时INVITE会经过该代理
  2. nat_traversal:我原本以为这个模块实施了nat table,但并没有。使用这个模块主要有以下两个作用
    1. 使用client_nat_test检测请求是否来自NATed主机
    2. 使用nat_keepalive来保持请求经过的节点的NAT记录
  3. cachedb_local:用来实施自己的nat table,可以替换成其他的cachedb
  4. dispatcher:负责out-dialog的非INVITE请求的代理
  5. ld_balancer:负责out-dialog的INVITE请求的代理

主要思想

  1. INVITE、REGISTER、SUBSCRIBE请求经过代理是,使用client_nat_test检测NAT,将来源是NATed主机登记到nat table中(目前的nat table很简单,就是NATed地址作为key,外部地址作为value,同时还增加了600秒的生命期)
  2. 当话机通过该代理进行注册时,通过add_path_received在Path中记录当前代理的地址以及请求的外部地址。(freeswitch-1.10.6存在bug,不能正确的让Path中的received参数生效,master中已经修正了该问题)
  3. 通过freeswitch呼叫外网的话机时,会将之前的Path作为Route,这样就保证了INVITE请求一定会经过该代理
  4. 通过loose_route获取转发的目的地
  5. 若$du非空,则使用$du从nat table中获取记录的外部地址,否则使用$ru进行查找
  6. 将$du更新成查找到的地址记录
  7. 转发请求

配置脚本

#
# OpenSIPS loadbalancer script
#     by OpenSIPS Solutions <team@opensips-solutions.com>
#
# This script was generated via "make menuconfig", from
#   the "Load Balancer" scenario.
# You can enable / disable more features / functionalities by
#   re-generating the scenario with different options.
#
# Please refer to the Core CookBook at:
#      https://opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#


####### Global Parameters #########
/* uncomment the following lines to enable debugging */
#debug_mode=yes

log_level=3
xlog_level=3
log_stderror=yes
log_facility=LOG_LOCAL0

udp_workers=1

/* uncomment the next line to enable the auto temporary blacklisting of 
   not available destinations (default disabled) */
#disable_dns_blacklist=no

/* uncomment the next line to enable IPv6 lookup after IPv4 dns 
   lookup failures (default disabled) 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值