fs_cli 命令行

概述

FreeSWITCH CLI (fs_cli) 是 FreeSWITCH 的命令行管理工具,用于实时控制和管理 FreeSWITCH。

快捷键配置文件: /conf/autoload_configs/switch.conf.xml


🔧 基础操作

进入/退出 CLI

1
2
3
4
5
6
7
8
# 进入 CLI
fs_cli

# 远程连接
fs_cli -x "命令"

# 退出
/exit 或 quit

帮助

1
2
3
4
5
# 查看所有命令
help

# 查看特定命令帮助
help <命令名>

📞 Sofia 调试命令

Profile 状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 列出某个 Profile 的状态
sofia status profile internal

# 列出某个 Profile 上所有已注册用户
sofia status profile internal reg

# 过滤符合条件的用户
sofia status profile internal reg 1000

# 列出某个特定用户
sofia status profile internal user 1000

# 列出所有 Profile
sofia status

网关管理

1
2
3
4
5
6
7
8
9
# 列出所有网关状态
sofia status gateway

# 列出特定网关状态
sofia status gateway gw-name

# 重启网关(修改配置后不重启 FreeSWITCH)
sofia profile external killgw gw-name
sofia profile external rescan

SIP 抓包

1
2
3
4
5
6
7
# 方法 1: 使用内置 homer
sofia profile internal capture on
sofia profile internal capture off

# 方法 2: siptrace 子命令
sofia global siptrace on
sofia global siptrace off

Debug 日志

1
2
3
4
5
# 仅开启 nua 模块的日志
sofia loglevel nua 9

# 设置整体日志级别
console loglevel 7

🎵 常用功能

回铃音测试

1
2
3
4
5
# 播放回铃音
originate user/1000 &echo()

# 指定回铃音
originate {ringback=%(2000,4000,440,480)}user/1000 &echo()

播放放音

1
2
3
4
5
# 播放音频文件
uuid_broadcast <uuid> play::misc/welcome.wav

# 播放并等待
uuid_park <uuid>

设置外显号码

1
2
3
4
5
# 发起呼叫时设置主叫号码
originate {origination_caller_id_number=13800138000}user/1001 &echo()

# 或使用 effective_caller_id_name
originate {effective_caller_id_name=张三,effective_caller_id_number=1001}user/1001 &echo()

呼叫并录音

1
2
3
4
5
6
# 启用录音
originate {record_path=/tmp/record.wav,record_append=true}user/1001 &echo()

# 实时开始录音
uuid_record <uuid> start /tmp/call.wav
uuid_record <uuid> stop /tmp/call.wav

🧪 正则校验

1
2
3
4
5
6
7
8
9
10
11
# 语法: regex <匹配的字符串>|<正则表达式>

# 测试匹配
regex 1234 | ^\d

# 输出: true (匹配成功) 或 false (匹配失败)

# 常用示例
regex 1001 | ^10\d{2}$
regex 912345678 | ^9(\d+)$
regex 5000 | ^5000$

📊 状态查询

通道状态

1
2
3
4
5
6
7
8
9
10
11
# 显示所有活动通道
show channels

# 显示详细通道信息
show detailed channels

# 显示通道数量
show channels count

# 显示特定通道
show channels <uuid>

呼叫状态

1
2
3
4
5
6
7
8
# 显示所有呼叫
show calls

# 显示详细呼叫信息
show detailed calls

# 显示呼叫数量
show calls count

分机状态

1
2
3
4
5
# 检查分机是否存在
user_exists <分机号>

# 查看注册用户
sofia status profile internal reg

🔍 调试技巧

实时日志

1
2
3
4
5
6
7
8
# 开启详细日志
console loglevel 7

# 只看特定模块日志
console loglevel 7 | grep sofia

# 查看错误日志
console loglevel | grep -i error

抓包分析

1
2
3
4
5
6
7
8
# 开启 SIP 抓包
sofia global siptrace on

# 保存到文件
sofia profile internal capture on

# 查看抓包内容
# 抓包文件位于 /usr/local/freeswitch/log/siptrace/

呼叫追踪

1
2
3
4
5
# 设置 UUID
uuid_setvar <uuid> process_cdr true

# 查看变量
uuid_getvar <uuid> <variable_name>

📝 配置重载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 重载 XML 配置
reloadxml

# 重载 Sofia 模块
reload mod_sofia

# 重载特定 Profile
sofia profile internal restart reloadxml

# 重载 Dialplan
reload mod_dialplan_xml

# 重载 ACL
reload mod_acl

🚨 常用操作

挂断呼叫

1
2
3
4
5
# 挂断指定呼叫
uuid_kill <uuid>

# 挂断所有呼叫
hupall

转移呼叫

1
2
3
4
5
# 转移到其他分机
uuid_transfer <uuid> 1001

# 转移到外部号码
uuid_transfer <uuid> 13800138000 XML default

变量操作

1
2
3
4
5
6
7
8
# 设置变量
uuid_setvar <uuid> variable_name value

# 获取变量
uuid_getvar <uuid> variable_name

# 显示所有变量
uuid_dump <uuid>

📚 相关文档


© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!