Remove stunaddr/turnaddr from rtp.conf — fixes STUN timeout causing 27s delay
Asterisk doesn't need STUN/TURN in rtp.conf for this setup because: - It already knows its public IP via external_media_address in pjsip.conf - Its RTP ports are port-forwarded, so host ICE candidates are sufficient - stunaddr/turnaddr caused STUN gather timeouts (~27s) on every call, whether pointing at the FQDN (DNS TTL=0 bug) or localhost (UDP timeout) coturn is for SIP *clients* behind strict NAT — they configure TURN in their own app settings, independently of Asterisk's rtp.conf. ICE support remains enabled so Asterisk participates in ICE negotiation. https://claude.ai/code/session_01KWVtEt9MmZdywcu7WmgchX
This commit is contained in:
+6
-5
@@ -17,7 +17,7 @@
|
|||||||
# - All SIP clients connect to DOMAIN_NAME:5061 (TLS)
|
# - All SIP clients connect to DOMAIN_NAME:5061 (TLS)
|
||||||
# - coturn handles NAT traversal (STUN) and media relay (TURN)
|
# - coturn handles NAT traversal (STUN) and media relay (TURN)
|
||||||
# - Works from any network: LAN, cellular, Proton VPN, hotel WiFi
|
# - Works from any network: LAN, cellular, Proton VPN, hotel WiFi
|
||||||
# - TURN credentials are auto-generated if TURN_PASSWORD is empty
|
# - Set TURN_PASSWORD below (generate one: openssl rand -base64 18)
|
||||||
# ================================================================
|
# ================================================================
|
||||||
|
|
||||||
# ── Domain Name (REQUIRED) ────────────────────────────────────
|
# ── Domain Name (REQUIRED) ────────────────────────────────────
|
||||||
@@ -60,11 +60,12 @@ VLAN_SUBNETS=
|
|||||||
|
|
||||||
# ── TURN/STUN Settings ──────────────────────────────────────
|
# ── TURN/STUN Settings ──────────────────────────────────────
|
||||||
# Used by coturn for TURN relay authentication.
|
# Used by coturn for TURN relay authentication.
|
||||||
# Both coturn and Asterisk must use the SAME password.
|
# If empty, defaults to "changeme" — set a real password for security.
|
||||||
# If empty, both default to "changeme" — set a real password here.
|
# Generate one with: openssl rand -base64 18
|
||||||
#
|
#
|
||||||
# These credentials are shared between coturn and Asterisk.
|
# These credentials are for coturn only. SIP clients that need TURN
|
||||||
# SIP clients do NOT need these - only the server uses them.
|
# relay (behind strict NAT) must configure the same credentials in
|
||||||
|
# their SIP app settings.
|
||||||
TURN_USERNAME=easyasterisk
|
TURN_USERNAME=easyasterisk
|
||||||
TURN_PASSWORD=
|
TURN_PASSWORD=
|
||||||
|
|
||||||
|
|||||||
+10
-12
@@ -279,24 +279,22 @@ EOF
|
|||||||
chown asterisk:asterisk /etc/asterisk/pjsip.conf
|
chown asterisk:asterisk /etc/asterisk/pjsip.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── rtp.conf (always regenerated - includes TURN credentials) ──
|
# ── rtp.conf (always regenerated) ──
|
||||||
# Use 127.0.0.1 for stunaddr/turnaddr because coturn runs on the same host
|
# ICE is enabled so Asterisk participates in ICE negotiation with clients.
|
||||||
# (network_mode: host). Using the FQDN would cause DNS resolution, and if the
|
# stunaddr/turnaddr are NOT set here because:
|
||||||
# DNS TTL is 0 Asterisk cancels recurring resolution — breaking ICE entirely
|
# - Asterisk already knows its public IP via external_media_address in pjsip.conf
|
||||||
# and adding a ~27-second timeout delay to every call.
|
# - Its RTP ports are port-forwarded, so host candidates are sufficient
|
||||||
turn_port="${turn_server##*:}"
|
# - Setting stunaddr/turnaddr causes STUN/TURN gather timeouts (~27s per call)
|
||||||
local_turn="127.0.0.1:${turn_port:-3478}"
|
# when the STUN/TURN server is unreachable or misconfigured
|
||||||
log_info "Configuring RTP with ICE + STUN + TURN (local: ${local_turn})..."
|
# coturn is for SIP CLIENTS behind strict NAT — they configure TURN in their
|
||||||
|
# own app settings, independently of Asterisk's rtp.conf.
|
||||||
|
log_info "Configuring RTP with ICE support..."
|
||||||
cat > /etc/asterisk/rtp.conf << EOF
|
cat > /etc/asterisk/rtp.conf << EOF
|
||||||
[general]
|
[general]
|
||||||
rtpstart=${RTP_START:-10000}
|
rtpstart=${RTP_START:-10000}
|
||||||
rtpend=${RTP_END:-20000}
|
rtpend=${RTP_END:-20000}
|
||||||
strictrtp=yes
|
strictrtp=yes
|
||||||
icesupport=yes
|
icesupport=yes
|
||||||
stunaddr=${local_turn}
|
|
||||||
turnaddr=${local_turn}
|
|
||||||
turnusername=${TURN_USERNAME}
|
|
||||||
turnpassword=${TURN_PASSWORD}
|
|
||||||
EOF
|
EOF
|
||||||
chown asterisk:asterisk /etc/asterisk/rtp.conf
|
chown asterisk:asterisk /etc/asterisk/rtp.conf
|
||||||
|
|
||||||
|
|||||||
@@ -3032,21 +3032,18 @@ transport=config,pjsip.conf,criteria=type=transport
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ICE / STUN / TURN configuration
|
# ICE configuration
|
||||||
# Enabled for: FQDN/internet mode OR VPN with ICE enabled
|
# ICE is enabled so Asterisk participates in ICE negotiation with clients.
|
||||||
|
# stunaddr/turnaddr are NOT set because:
|
||||||
|
# - Asterisk knows its public IP via external_media_address in pjsip.conf
|
||||||
|
# - Its RTP ports are port-forwarded, so host candidates are sufficient
|
||||||
|
# - Setting stunaddr/turnaddr causes STUN/TURN gather timeouts (~27s delay)
|
||||||
|
# coturn (if running) is for SIP clients behind strict NAT — they configure
|
||||||
|
# TURN in their own app settings, independently of Asterisk's rtp.conf.
|
||||||
load_config
|
load_config
|
||||||
local ice_config=""
|
local ice_config=""
|
||||||
if [[ -n "$DOMAIN_NAME" ]] || [[ "$VPN_ICE_ENABLED" == "y" ]] || [[ "$TURN_ENABLED" == "y" ]]; then
|
if [[ -n "$DOMAIN_NAME" ]] || [[ "$VPN_ICE_ENABLED" == "y" ]] || [[ "$TURN_ENABLED" == "y" ]]; then
|
||||||
local stun_addr="${TURN_SERVER:-${CUSTOM_STUN_SERVER:-stun.l.google.com:19302}}"
|
ice_config="icesupport=yes"
|
||||||
ice_config="icesupport=yes
|
|
||||||
stunaddr=${stun_addr}"
|
|
||||||
# Add TURN relay if configured (required for calls through strict NAT/VPN)
|
|
||||||
if [[ "$TURN_ENABLED" == "y" && -n "$TURN_SERVER" && -n "$TURN_USERNAME" && -n "$TURN_PASSWORD" ]]; then
|
|
||||||
ice_config="${ice_config}
|
|
||||||
turnaddr=${TURN_SERVER}
|
|
||||||
turnusername=${TURN_USERNAME}
|
|
||||||
turnpassword=${TURN_PASSWORD}"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
ice_config="# icesupport disabled - LAN only mode"
|
ice_config="# icesupport disabled - LAN only mode"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user