接通后秒挂 - ICE/STUN 问题
🔥 问题现象
接通后立即挂断,日志显示 STUN/ICE 错误。
🚨 完整日志
日志片段 1: STUN/ICE 错误持续出现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| 2025-05-21 13:37:29.746896 100.00% [DEBUG] sofia.c:7493 Channel sofia/internal/1002@192.168.232.225 entering state [early][183] 2025-05-21 13:37:29.766994 100.00% [WARNING] switch_core_file.c:463 File has 2 channels, muxing to 1 channel will occur. 2025-05-21 13:37:29.766994 100.00% [DEBUG] switch_ivr_play_say.c:1561 Codec Activated L16@48000hz 1 channels 20ms 2025-05-21 13:37:30.056176 100.00% [NOTICE] switch_rtp.c:1440 Auto Changing audio stun/rtp/dtls port from 192.168.100.46:18235 to 192.168.236.163:56386 idx:-1 2025-05-21 13:37:30.075647 100.00% [DEBUG] switch_rtp.c:1934 rtcp_stats_init: audio ssrc[723459006] base_seq[0] 2025-05-21 13:37:30.126895 100.00% [WARNING] switch_rtp.c:1047 sofia/internal/1002@192.168.232.225 got audio stun binding response 487 2025-05-21 13:37:30.126895 100.00% [WARNING] switch_rtp.c:1058 audio STUN Changing role to CONTROLLED 2025-05-21 13:37:30.186982 100.00% [WARNING] switch_rtp.c:1047 sofia/internal/1002@192.168.232.225 got audio stun binding response 487 2025-05-21 13:37:30.186982 100.00% [WARNING] switch_rtp.c:1055 audio STUN Changing role to CONTROLLING 2025-05-21 13:37:31.206936 100.00% [WARNING] switch_rtp.c:1047 sofia/internal/1002@192.168.232.225 got audio stun binding response 487 2025-05-21 13:37:31.206936 100.00% [WARNING] switch_rtp.c:1058 audio STUN Changing role to CONTROLLED 2025-05-21 13:37:45.806935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:38:01.666935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:38:17.246935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:38:32.586935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:38:47.926935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:39:03.086891 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:39:18.386936 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:39:33.626939 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:39:48.966893 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:40:04.166935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes 2025-05-21 13:40:19.386935 100.00% [ERR] switch_rtp.c:1008 Invalid STUN/ICE packet received 28 bytes
|
日志片段 2: 呼叫中途取消
1 2 3 4 5 6 7 8 9 10 11 12
| 2025-05-20 17:03:26.627561 100.00% [DEBUG] switch_ivr_originate.c:1363 Raw Codec Activation Success L16@48000hz 1 channel 20ms 2025-05-20 17:03:26.627561 100.00% [DEBUG] switch_core_codec.c:250 sofia/internal/8001@192.168.232.225 Push codec L16:100 2025-05-20 17:03:26.627561 100.00% [DEBUG] switch_ivr_originate.c:1437 Play Ringback Tone [%(2000,4000,440,480)] 2025-05-20 17:03:26.667578 100.00% [DEBUG] sofia.c:7493 Channel sofia/internal/8001@192.168.232.225 entering state [early][183] 2025-05-20 17:03:26.767674 100.00% [NOTICE] switch_rtp.c:1440 Auto Changing audio stun/rtp/dtls port from 192.168.63.229:40465 to 192.168.232.225:62353 idx:-1 2025-05-20 17:03:26.827534 100.00% [DEBUG] switch_rtp.c:1934 rtcp_stats_init: audio ssrc[3092357378] base_seq[0] 2025-05-20 17:03:26.847601 100.00% [WARNING] switch_rtp.c:1047 sofia/internal/8001@192.168.232.225 got audio stun binding response 487 2025-05-20 17:03:26.847601 100.00% [WARNING] switch_rtp.c:1058 audio STUN Changing role to CONTROLLED 2025-05-20 17:03:28.913316 100.00% [DEBUG] sofia.c:7493 Channel sofia/internal/8001@192.168.232.225 entering state [terminated][487] 2025-05-20 17:03:28.913316 100.00% [NOTICE] sofia.c:8736 Hangup sofia/internal/8001@192.168.232.225 [CS_EXECUTE] [ORIGINATOR_CANCEL] 2025-05-20 17:03:28.913316 100.00% [DEBUG] switch_core_codec.c:275 sofia/internal/8001@192.168.232.225 Restore previous codec opus:116. 2025-05-20 17:03:28.913316 100.00% [NOTICE] switch_ivr_originate.c:3820 Hangup sofia/internal/1001@192.168.232.225:54251 [CS_CONSUME_MEDIA] [ORIGINATOR_CANCEL
|
🔍 根本原因
ICE/STUN 开启导致编解码器不匹配,内网环境不需要 NAT 穿透。
✅ 解决方案
1. 检查客户端
关闭分机的 ICE/STUN 设置,重新注册。
2. 修改 vars.xml
1
| <X-PRE-PROCESS cmd="set" data="sip_stun_enabled=false"/>
|
3. 修改 sip_profiles/internal.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <profile name="internal"> <param name="enable-ice" value="false"/> <param name="stun-enabled" value="false"/> <param name="rtcp-mux" value="false"/>
<param name="aggressive-nat-detection" value="false"/> <param name="nat-options-ping" value="false"/> <param name="all-reg-options-ping" value="false"/>
<param name="rtp-ip" value="192.168.232.225"/> <param name="sip-ip" value="192.168.232.225"/> <param name="ext-rtp-ip" value="192.168.232.225"/> <param name="ext-sip-ip" value="192.168.232.225"/>
<param name="NDLB-force-rport" value="false"/> <param name="NDLB-received-in-nat-reg-contact" value="false"/> </profile>
|
4. 重载配置
1 2
| fs_cli -x "reloadxml" fs_cli -x "sofia profile internal restart reloadxml"
|
💡 适用场景
🔍 验证修复
1 2 3 4 5
| tail -f /usr/local/freeswitch/log/freeswitch.log | grep -i "stun\|ice"
fs_cli -x "originate user/1001 &echo()"
|
预期结果:
- ✅ 无
Invalid STUN/ICE packet received 错误
- ✅ 无
STUN Changing role 警告
- ✅ 呼叫正常建立
- ✅ 通话保持稳定
📚 相关文档