查看配置
show 配置模式命令可显示运行 Junos OS 的设备的当前配置。
显示当前的 Junos OS 配置
要显示运行 Junos OS 的设备的当前配置,请在配置模式中使用 show 命令。此命令显示当前层级或指定层级的配置。
user@host# show <statement-path>
配置语句将以固定顺序出现,接口将先按类型的字母顺序,然后按插槽编号、PIC 编号和端口号的数字顺序排列。请注意,配置路由器时,您可以按任意顺序输入语句。
您还可以使用 CLI 操作模式 show configuration 命令显示最近提交的配置,即当前在路由器上运行的配置:
user@host> show configuration
显示配置时,位于配置顶部的时间戳标明了最近更改配置的时间:
## Last commit: 2018-07-18 11:21:58 PDT by echen
version 8.3
如果在配置模式下发出 show 命令时在某个特定层级省略了必需的语句,则会出现一条消息,指示缺少哪条语句。如果缺少必需语句,则 CLI 将在每次发出 show 命令时继续显示此消息。例如:
[edit]
user@host# show
protocols {
pim {
interface so-0/0/0 {
priority 4;
version 2;
# Warning: missing mandatory statement(s): 'mode'
}
}
}
显示了 CLI 配置中包含的不受支持的语句,配置中有 “ 不支持 ” 的文本。例如当在不受支持的平台上配置语句时,CLI 将显示一条消息,说明将在配置中忽略该语句,因为该语句配置在了不受支持的平台上。使用 | display xml 选项发出 show 命令时,您可以看到不受支持的配置的 unsupported="unsupported” 属性。
当 <get-configuration> RPC 调用中包含 unsupported="unsupported" 属性时,将向脚本提供在文本配置或 XML 配置中包含的 “ 不支持的 ” 属性。
示例:显示当前的 Junos OS 配置
设置并提交配置:
[edit]
user@host# set protocols ospf area 0.0.0.0 interface
so-0/0/0 hello-interval 5
[edit]
user@host# commit
commit complete
[edit]
user@host# quit
exiting configuration mode
显示当前配置:
[edit]
user@host# show
protocols {
ospf {
area 0.0.0.0 {
interface so-0/0/0 {
hello-interval 5;
}
}
}
}
显示特定层级的配置:
[edit]
user@host# show protocols ospf area 0.0.0.0
interface so-0/0/0 {
hello-interval 5;
}
下移一个级别并显示该级别的配置:
[edit]
user@host# edit protocols ospf area 0.0.0.0
[edit protocols ospf area 0.0.0.0]
user@host# show
interface so-0/0/0 {
hello-interval 5;
}
显示上一次提交的配置:
user@host> show configuration
## Last commit: 2018-08-10 11:21:58 PDT by user
version 8.3
protocols {
ospf {
area 0.0.0.0 {
interface so-0/0/0 {
hello-interval 5;
}
}
}
}
要显示有关配置的附加信息,请在竖线 ( | ) 后结合 show 命令一起使用 display detail 命令,仅限配置模式。附加信息包括帮助字符串,这些字符串可以解释添加和修改配置语句所需的每个配置语句和权限位。
user@host# show <hierarchy-level> | display detail
例如:
[edit]
user@host# show | display detail
##
## version: Software version information
## require: system
##
version "18.2R1 [tlim]";
system {
##
## host-name: Host name for this router
## match: ^[[:alnum:]._-]+$
## require: system
##
}
host-name router-name;
##
## domain-name: Domain name for this router
## match: ^[[:alnum:]._-]+$
## require: system
##
domain-name isp.net;
##
## backup-router: Address of router to use while booting
##
backup-router 192.168.100.1;
root-authentication {
##
## encrypted-password: Encrypted password string
##
encrypted-password "$ABC123"; # SECRET-DATA
}
##
## name-server: DNS name servers
## require: system
##
name-server {
##
## name-server: DNS name server address
##
208.197.1.0;
}
login {
##
## class: User name (login)
## match: ^[[:alnum:]_-]+$
##
class super-user {
##
## permissions: Set of permitted operation categories
##
permissions all;
}
...
##
## services: System services
## require: system
##
services {
## services: Service name
##
ftp;
##
## services: Service name
##
telnet;
##
}
syslog {
##
## file-name: File to record logging data
##
file messages {
##
## Facility type
## Level name
##
any notice;
##
## Facility type
## Level name
##
authorization info;
}
}
}
chassis {
alarm {
sonet {
##
## lol: Loss of light
## alias: loss-of-light
##
lol red;
}
}
}
interfaces {
##
## Interface name
##
at-2/1/1 {
atm-options {
##
## vpi: Virtual path index
## range: 0 .. 255
## maximum-vcs: Maximum number of virtual circuits on this
VP
##
vpi 0 maximum-vcs 512;
}
##
## unit: Logical unit number
## range: 0 .. 16384
##
unit 0 {
##
## vci: ATM point-to-point virtual circuit identifier ([vpi.]vci)
}
##
vci 0.128;
}
}
...
  
显示 Junos OS 配置中的 set 命令
在配置模式下,您可以将配置显示为重新创建配置所需的一系列配置模式命令。如果您不熟悉如何使用配置模式命令,或者想要剪切、粘贴和编辑显示的配置,上述功能会很有用。
要将配置显示为从层次结构顶层将配置重新创建为 set 命令所需的一系列配置模式命令,请发出带有 display set 选项的 show 配置模式命令:
user@host# show | display set
当使用 | display set 管道选项发出 show configuration 命令,从而以 set 命令的形式查看配置时,您没有权限查看的配置部分将被替换为文本 ACCESS-DENIED。
本主题包含以下示例:
示例:显示配置中的 set 命令
在 [edit interfaces] 层级显示配置中的 set 命令:
[edit interfaces fe-0/0/0]
user@host# show
unit 0 {
family inet {
address 192.107.1.230/24;
}
family iso;
family mpls;
}
inactive: unit 1 {
family inet {
address 10.0.0.1/8;
}
}
[edit interfaces fe-0/0/0]
user@host# show | display set
set interfaces fe-0/0/0 unit 0 family inet address 192.107.1.230/24
set interfaces fe-0/0/0 unit 0 family iso
set interfaces fe-0/0/0 unit 0 family mpls
set interfaces fe-0/0/0 unit 1 family inet address 10.0.0.1/8
deactivate interfaces fe-0/0/0 unit 1
要将配置显示为从当前层级重新创建配置的一系列配置模式命令,请发出带有 display set relative 的 show 配置模式命令选项:
[edit interfaces fe-0/0/0]
user@host# show | display set relative
set unit 0 family inet address 192.107.1.230/24
set unit 0 family iso
set unit 0 family mpls
set unit 1 family inet address 10.0.0.1/8
deactivate unit 1
示例:显示带有匹配选项的 set 命令
要将配置显示为 set 命令并使用过滤输出搜索与正则表达式匹配的文本,请在竖线 (|) 后指定 match 选项:
user@host# show | display set | match regular-expression
显示与某个接口相关联的 IP 地址:
xe-2/3/0 {
unit 0 {
family inet {
address 192.107.9.106/30;
}
}
}
so-5/1/0 {
unit 0 {
family inet {
address 192.107.9.15/32 {
destination 192.107.9.192;
}
}
}
}
lo0 {
unit 0 {
family inet {
address 127.0.0.1/32;
}
}
}
user@host# show interfaces | display set | match address
set interfaces xe-2/3/0 unit 0 family inet address 192.168.9.106/30
set interfaces so-5/1/0 unit 0 family inet address 192.168.9.15/32
destination 192.168.9.192
set interfaces lo0 unit 0 family inet address 127.0.0.1/32