mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-20 13:50:45 +08:00
13 KiB
13 KiB
命令探索方法论:通过 ? 在线帮助发现真实命令
为什么需要命令探索?
在实际网络运维中,我们经常遇到以下问题:
- 文档过时:厂商设备版本升级后命令语法变化
- 记忆模糊:记不清完整命令路径和参数格式
- 设备差异:不同厂商(ZTE/Huawei/Cisco)命令体系不同
- 上下文依赖:某些命令只在特定模式下可用
解决方案:使用设备内置的 ? 在线帮助系统,像"剥洋葱"一样逐层探索。
核心原则:从宽到窄,逐步细化
探索路径示例:以BGP VPNv4路由查询为例
第一步:确定顶层命令
MER1#show ?
输出会列出所有 show 开头的命令类别:
bgp Show BGP information
ip Show IP information
mpls Show MPLS information
isis Show IS-IS routing information
...
第二步:进入子命令层级
MER1#show bgp ?
输出显示BGP相关的地址族:
ipv4 IPv4 address family
vpnv4 VPNv4 address family
evpn Display information about all EVPN NLRIs
...
第三步:继续深入具体类型
MER1#show bgp vpnv4 ?
输出显示VPNv4的单播/组播分类:
unicast Display information about all VPNv4 NLRIs
multicast Display information about all VPNv4 multicast NLRIs
flowspec Flow specification address family modifier
...
第四步:查看可用的操作符和参数
MER1#show bgp vpnv4 unicast ?
关键输出(这是最有价值的一步):
as Autonomous system
community Show route community information
dampened-paths Show paths suppressed due to dampening
detail Display detailed information about an ip prefix
flap Show flap info
in Show route information received from all neighbors
labels Display BGP labels for prefixes
neighbor Detailed information on TCP and BGP neighbor connections
network Show route information
rd Specify route distinguisher
rd-by-vrf Specify route distinguisher by VRF name
vrf Display information for a VPN Routing/Forwarding instance
| Output modifiers (管道符,用于过滤)
> Redirect the output to a file (重定向到文件)
<cr> Carriage return (直接回车执行)
第五步:选择VRF相关选项继续探索
MER1#show bgp vpnv4 unicast vrf ?
输出显示可用的VRF实例名称:
5G_MEC VPN Routing/Forwarding instance name
IP_RAN VPN Routing/Forwarding instance name
test VPN Routing/Forwarding instance name
WORD VPN Routing/Forwarding instance name (任意字符串)
第六步:查看VRF下的具体操作
MER1#show bgp vpnv4 unicast vrf test ?
最终得到精确命令:
detail Show route detail information
export-unicast Export VRF routes to unicast routing table
import-unicast Import unicast routes to VRF routing table
in Show route information received from all neighbors
labels Display BGP labels for prefixes
local Display local information of a BGP neighbor
neighbor Detailed information on TCP and BGP neighbor connections
policy Display information about bgp advertisements under a proposed policy
received Display information received from a BGP neighbor
route Show route information ← 这就是我们要的!
summary Summary of BGP neighbor status
第七步:执行最终命令
MER1#show bgp vpnv4 unicast vrf test route
输出完整的BGP VPNv4路由表:
15:21:26 Beijing Mon Jul 20 2026
Current AS: 100. Other AS: 64580, 64600, 64900
Status codes: * valid, > best, i - internal, s - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf RtPrf Path
实战案例:探索Ping和Trace命令
案例1:VRF环境下的Ping命令
探索过程记录
# 第1层:ping后面可以跟什么?
MER1#ping ?
A.B.C.D Target IP address
bier Send BIER echo messages
ce Customer edge
dcn DCN VRF
domain Domain name
evpn Send EVPN echo messages
mpls Send MPLS echo messages
satellite Specify satellite ID
vpls VPLS instance
vpws Kompella VPWS
vrf VPN Routing/Forwarding instance name
# 第2层:ping vrf后面跟什么?
MER1#ping vrf ?
5G_MEC VRF name (1-32 characters)
5G_OAM VRF name (1-32 characters)
IP_RAN VRF name (1-32 characters)
test VRF name (1-32 characters)
WORD VRF name (1-32 characters)
# 第3层:ping vrf test后面跟什么?
MER1#ping vrf test ?
A.B.C.D Target IP address
domain Domain name
# 第4层:执行完整命令
MER1#ping vrf test 4.1.1.1
sending 5,100-byte ICMP echo(es) to 4.1.1.1,timeout is 2 second(s).
.....
Success rate is 0 percent(0/5).
案例2:探索MPLS LDP邻居查询
# 第1层:mpls ldp后面有什么?
MER1#show mpls ldp ?
backoff Show LDP session setup backoff table
bindings Show the LDP label information base (LIB)
discovery Show sources for locally generated LDP discovery hello PDUs
graceful-restart Show MPLS LDP GR
iccp Show LDP session and ICCP state information
igp Show LDP IGP synchronization status
instance Show LDP instance information
interface Show per-interface LDP forwarding information
log Show LDP log info
neighbor Show LDP neighbor information ← 目标在这里
parameters Show LDP configuration parameters
# 第2层:neighbor后面有什么?
MER1#show mpls ldp neighbor ?
A.B.C.D Neighbor address
brief Brief neighbor information ← 要这个简洁版
bvi Bvi interface
detail Detailed neighbor information
graceful-restart The information of LDP graceful restart neighbor
instance The information of LDP instance ← 还可以指定实例
# 第3层:instance后面跟什么?
MER1#show mpls ldp neighbor brief instance ?
<1-65535> LDP instance id
# 第4层:执行完整命令
MER1#show mpls ldp neighbor brief instance 1
15:20:54 Beijing Mon Jul 20 2026
Codes: D:Direct, T:Targeted, D&T:Direct&Targeted
Total number of neigbors:0
Operational:0 (D:0,T:0,D&T:0) (IPv4:0,IPv6:0,IPv4&IPv6:0)
Not operational:0 (D:0,T:0,D&T:0) (IPv4:0,IPv6:0,IPv4&IPv6:0)
高级技巧:组合使用 ? 和其他工具
技巧1:利用 <cr> 提示判断命令完整性
当 ? 输出中包含 <cr> 时,表示当前命令已经完整,可以直接执行:
MER1#show mpls ldp neighbor brief instance 1 ?
<cr> ← 看到这个,就知道可以直接回车执行了
技巧2:使用管道符 | 过滤大量输出
当某个命令输出太多时,用 ? 查看可用的过滤选项:
MER1#show bgp vpnv4 unicast vrf test route ?
| Output modifiers
MER1#show bgp vpnv4 unicast vrf test route | ?
begin Begin with the line that matches
count Count the number of lines that match
exclude Exclude lines that match
include Include lines that match
section Print only the section that matches
# 实际应用:只看包含特定前缀的路由
MER1#show bgp vpnv4 unicast vrf test route | include 4.1.1
技巧3:在配置模式下同样适用
? 不仅适用于特权模式(#),也适用于配置模式((config)#):
MER1#configure terminal
MER1(config)#router bgp 100
MER1(config-bgp-router)#neighbor ?
A.B.C.D Neighbor IPv4 address
X:X::X:X Neighbor IPv6 address
peer-group Name of peer group
MER1(config-bgp-router)#neighbor 10.26.63.152 ?
activate Enable the neighbor
advertisement-interval Set minimum interval between sending routing updates
allowas-in Allow AS in path
...
next-hop-self Disable the next hop calculation for this neighbor ← 关键配置!
...
技巧4:识别命令缩写规则
通过 ? 可以发现命令的简写形式:
MER1#sh ?
show Show running system information
MER1#show mpls forw ?
forwarding-table Show MPLS forwarding-table information ← forw是forwarding的合法缩写
规律:只要输入的字母能唯一标识一个命令,就可以缩写。例如:
show→shforwarding-table→forwconfiguration→conf
常见命令树结构对比
ZTE vs Huawei vs Cisco
| 功能 | ZTE (ZXROS) | Huawei (VRP) | Cisco (IOS) |
|---|---|---|---|
| 查看BGP VPNv4路由 | show bgp vpnv4 unicast vrf <name> route |
display bgp vpnv4 routing-table vpn-instance <name> |
show bgp vpnv4 unicast vrf <name> |
| 查看MPLS转发表 | show mpls forwarding-table |
display mpls lsp |
show mpls forwarding-table |
| 查看LDP邻居 | show mpls ldp neighbor brief instance 1 |
display mpls ldp session |
show mpls ldp neighbor |
| Ping VRF内地址 | ping vrf <name> <ip> |
ping -vpn-instance <name> <ip> |
ping vrf <name> <ip> |
结论:虽然命令相似,但细节有差异。必须针对每种设备单独探索。
错误处理与注意事项
注意1:命令前缀限制
某些平台可能限制特定命令的使用:
# 如果收到 "command_not_allowed_prefix" 错误
MER1#trace vrf test 4.1.1.1
%Error: command_not_allowed_prefix
原因:trace 命令可能被netx等平台限制。此时应尝试:
- 改用完整路径
traceroute - 检查权限级别
- 使用替代命令(如通过ping逐跳测试)
注意2:区分"不完整命令"和"无匹配"
# 不完整命令(Incomplete command)- 说明方向对,继续用?探索
MER1#show bgp vpnv4 unicast vrf test
%Error 140305: Incomplete command.
# 无匹配(Unrecognized command)- 说明走错路了,退回上一层
MER1#show bgp vpnv4 unicast vrf test xyz
%Error: Unrecognized command.
注意3:空格敏感性
# 正确:每个层级之间有空格
MER1#show mpls ldp neighbor brief instance 1
# 错误:连在一起会当成一个单词
MER1#show mplsldpneighborbriefinstance1
%Error: Unrecognized command.
练习:自主探索以下命令
请用 ? 方法探索下列命令的完整语法(答案不唯一):
- 查看ISIS邻接关系
- 查看OSPF邻居详细信息
- 查看VRF IP_RAN的路由表
- 查看MPLS标签绑定信息
- 查看BGP从邻居10.26.63.152收到的路由
参考答案(实际以设备为准):
# 1. ISIS邻接
MER1#show isis adjacency
# 2. OSPF邻居详细
MER1#show ip ospf neighbor detail
# 3. VRF IP_RAN路由
MER1#show ip forwarding route vrf IP_RAN
# 4. MPLS标签绑定
MER1#show mpls ldp bindings
# 5. BGP从邻居收到的路由
MER1#show bgp vpnv4 unicast vrf test received 10.26.63.152
总结:命令探索五步法
- 定方向:从最顶层开始(
show ?,ping ?,configure ?) - 剥洋葱:每层用
?查看下一级选项,选择最相关的分支 - 看提示:注意
<cr>、WORD、A.B.C.D等元提示 - 试执行:看到
<cr>就执行,观察输出验证猜测 - 记笔记:把成功的命令路径记录下来(就像本文档做的)
终极心法:不要怕敲错,? 永远不会嘲笑你。每个网络专家都是从不停地敲 ? 开始的。
附录:快速参考卡片
# 通用探索模板
<command> ? # 查看下一级选项
<command> <subcommand> ? # 继续深入
...
<full-command> <cr> # 看到<cr>就可以执行
# 特殊符号含义
<cr> - 可以直接回车执行
WORD - 任意字符串(通常是名字、ID等)
A.B.C.D - IPv4地址格式
X:X::X:X - IPv6地址格式
<1-65535> - 数字范围
| - 管道符,用于过滤输出
> - 重定向到文件
# 经典命令树深度
show bgp vpnv4 unicast vrf <name> route # 7层
show mpls ldp neighbor brief instance <id> # 6层
ping vrf <name> <ip> # 4层
configure terminal # 2层
文档版本:v1.0
最后更新:2026-07-20
维护者:基于真实设备(MER1)验证