Nat

Asterisk 不使用 externip

  • July 16, 2015

我正在嘗試使用 hello-world 範例設置位於 NAT 後面的雲 Asterisk 伺服器。我有 NAT 問題。Asterisk 通過 SDP 提供給客戶端的 IP 地址是它在 NAT 後面的本地地址,而不是外部地址。

我試圖在 中設置externipsip.conf,但這似乎沒有效果。

[general]
externip=xxx.yyy.zzz.vvv
nat=yes
tcpenable=yes

externip客戶端收到的SDP與伺服器設置不一致:

v=0
o=root 291445984 291445984 IN IP4 172.31.46.110
s=Asterisk PBX 11.7.0~dfsg-1ubuntu1
c=IN IP4 172.31.46.110
t=0 0
m=audio 10078 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv
m=video 0 RTP/AVP 96

我希望 SDP 中的地址與externip欄位中提供的地址相匹配。我已經嘗試了實際的 IP 地址以及伺服器名稱,它通過 DNS 正確解析為 IP 地址。

我設置的externip值不正確嗎?或者是否需要其他設置才能讓 Asterisk 公佈其外部 IP 地址?

你忘了設置localnet。配置文件確實警告您必須將其設置為等於本地網路的網路塊。

;----------------------------------------- NAT SUPPORT ------------------------
;
; WARNING: SIP operation behind a NAT is tricky and you really need
; to read and understand well the following section.
;
; When Asterisk is behind a NAT device, the "local" address (and port) that
; a socket is bound to has different values when seen from the inside or
; from the outside of the NATted network. Unfortunately this address must
; be communicated to the outside (e.g. in SIP and SDP messages), and in
; order to determine the correct value Asterisk needs to know:
;
; + whether it is talking to someone "inside" or "outside" of the NATted network.
;   This is configured by assigning the "localnet" parameter with a list
;   of network addresses that are considered "inside" of the NATted network.
;   IF LOCALNET IS NOT SET, THE EXTERNAL ADDRESS WILL NOT BE SET CORRECTLY.
;   Multiple entries are allowed, e.g. a reasonable set is the following:
;
;      localnet=192.168.0.0/255.255.0.0 ; RFC 1918 addresses
;      localnet=10.0.0.0/255.0.0.0      ; Also RFC1918
;      localnet=172.16.0.0/12           ; Another RFC1918 with CIDR notation
;      localnet=169.254.0.0/255.255.0.0 ; Zero conf local network

實際上,取消所有四個範例localnet指令的註釋並收工通常沒問題。

(而且您應該大聲抱怨您的服務提供商缺乏 IPv6 支持…)

引用自:https://serverfault.com/questions/706108