在本页
修改设备配置
您可以通过 CLI 修改现有 Junos OS 配置。本节介绍如何添加语句、删除语句、复制语句和插入新标识符,包括示例。
显示当前正在编辑配置的用户
要显示当前正在编辑配置的用户,请使用 status
配置模式命令:
user@host# status
Users currently editing the configuration:
rchen terminal p0 (pid 55691) on since 2018-03-01 13:17:25 PST
[edit interfaces]
系统显示谁正在编辑配置 (rchen
)、用户登录的位置 (terminal p0
)、用户登录的日期和时间 (2018-03-01 13:17:25
PST
),以及用户正在编辑 ([edit interfaces]
)。
如果您发出 status
配置模式命令,而用户已将候选配置安排在未来一段时间内变为活动状态,系统将显示计划提交 (root
) 的人员、用户登录的位置 (terminal d0
)、用户登录的日期和时间 (2018-10-31 14:55:15 PST
),以及提交处于挂起状态 (commit at).
[edit]
user@host# status
Users currently editing the configuration:
root terminal d0 (pid 767) on since 2018-10-31 14:55:15 PST, idle 00:03:09
commit at
如果发出 status
配置模式命令,而用户在配置排他模式下编辑配置,系统将显示正在编辑配置 (root
)、用户登录的位置 (terminal d0
)、用户登录的日期和时间 (2018-11-01 13:05:11 PST
),以及用户正在配置排他模式 (exclusive [edit]
) 中编辑配置 。
[edit]
user@host# status
Users currently editing the configuration:
root terminal d0 (pid 2088) on since 2018-11-01 13:05:11 PST
exclusive [edit]
另请参阅
如何修改瞻博网络设备配置
要配置瞻博网络设备或修改现有配置,请使用 and set
命令在配置edit
中添加语句。对于每个语句层次结构,您都会创建以顶层语句开始的层次结构。然后,您继续创建语句,语句在层次结构中逐渐降低。
要修改层次结构,请使用两个配置模式命令。根据要完成的任务选择相关命令:
edit
- 移动到指定的层级。如果不存在该层次结构级别,命令将edit
创建它。命令edit
使用以下语法:edit <statement-path>
set
-创建配置语句并设置标识符值。发出set
命令后,您仍处于同一层级。命令set
使用以下语法:set <statement-path> statement <identifier>
配置语句和语句本身的层次结构为
statement-path
。如果已移动到语句的层次结构级别,则可以省略语句路径。配置语句本身是statement
。字符串identifier
标识语句的实例。
语句可以是容器语句,也可以是叶语句。容器语句可以包含其他容器语句,也可以包含叶语句。然而,只有一个枝叶声明。命令 edit?
将显示容器语句,同时 set?
同时显示容器语句和叶语句,用于 >
区分它们。
不能使用 edit
命令更改标识符的值。您必须使用 set
命令。
另请参阅
如何添加配置语句和标识符
您可以通过在配置中包含语句来配置瞻博网络设备的所有属性。语句由一个关键词组成,这是固定文本。您还可以在语句中包含标识符。标识符是您定义的识别名称,例如接口名称或用户名,使您能够和 CLI 在语句集合中区别对待。
例如,以下列表显示了配置模式中顶层的可用语句:
user@host# set ?
Possible completions:
> accounting-options Accounting data configuration
+ apply-groups Groups from which to inherit configuration data
> chassis Chassis configuration
> class-of-service Class-of-service configuration
> firewall Define a firewall configuration
> forwarding-options Configure options to control packet sampling
> groups Configuration groups
> interfaces Interface configuration
> policy-options Routing policy option configuration
> protocols Routing protocol configuration
> routing-instances Routing instance configuration
> routing-options Protocol-independent routing option configuration
> snmp Simple Network Management Protocol
> system System parameters
语句名称前的尖括号 ( >
) 表示它是容器语句,您可以在其下方的级别定义其他语句。如果语句名称前没有尖括号 ( >
),则语句为叶语句;您不能在它下的层次结构级别上定义其他语句。
语句名称前的加号 (+) 表示它可以包含一组值。要指定一个集,请将值包含在括号内。例如:
[edit]
user@host# set policy-options community my-as1-transit members [65535:10 65535:11]
在某些语句中,您可以包含标识符。对于某些标识符(如接口名称),必须以精确格式指定标识符。例如,接口名称 so-0/0/0 是指位于插槽 0、第一个 PIC 位置和物理接口卡 (PIC) 上的第一个端口上的灵活 PIC 集中器 (FPC) 上的 SONET/SDH 接口。
对于其他标识符,如接口描述性文本、策略和防火墙术语名称,您可以指定任何名称,包括特殊字符、空格和制表符。
必须将标识符括在引号(双引号)中。您还必须使用引号将标识符和包含空格、制表符或以下任一字符的任何字符串括起来:
( ) [ ] { } ! @ # $ % ^ & | ' = ?
如果未为需要选项的语句键入选项,则将显示一条消息,指示所需的信息类型。在此示例中,必须键入一个区号才能完成命令:
[edit]
user@host# set protocols ospf area
^
syntax error, expecting <identifier>
另请参阅
如何从设备配置中删除语句
使用 delete
配置模式命令从设备配置中删除语句或标识符。删除语句或标识符会有效地“取消配置”与该语句或标识符关联的功能,使该功能恢复为默认条件。
user@host# delete <statement-path> <identifier>
删除语句时,将从配置中移除语句及其所有从属语句和标识符。
对于可以具有多个标识符的语句,删除一个标识符时,只会删除该标识符。语句中的其他标识符保留下来。
要从当前层次结构级别开始删除整个层次结构,请使用 delete
命令,而不指定语句或标识符。省略语句或标识符时,系统会提示您确认删除:
[edit]
user@host# delete
Delete everything under this level? [yes, no] (no)
Possible completions:
no Don't delete everything under this level
yes Delete everything under this level
Delete everything under this level? [yes, no] (no)
您无法使用单个 delete
命令删除层次结构中的多个语句或标识符。您必须使用多个 delete
命令分别删除每个语句或标识符。例如,考虑在层次结构级别上的 [edit system]
以下配置:
system { host-name host-211; domain-name domain-122; backup-router 192.168.71.254; arp; authentication-order [ radius password tacplus ]; }
要从配置中删除 domain-name
、 host-name
和 backup-router
,必须分别删除每个语句。
user@hostdelete system host-name host-211
user@hostdelete system domain-name domain-122
user@hostdelete system backup-router 192.168.71.254
不能发出单个 delete
命令。例如,以下命令不起作用:
user@host> delete system hostname host-211 domain-name domain-122 backup-router 192.168.71.254
您可以使用单个命令和正则表达式同时删除相关配置项目,例如通道化接口或静态路由。删除语句或标识符会有效地“取消配置”与该语句或标识符关联的功能,使该功能恢复为默认条件。
您只能删除配置中通常放置多个项目的某些部分,例如接口。但是,您不能删除不同项目的“组”,如此示例所示:
user@host#show system services
ftp; rlogin; rsh; ssh { root-login allow; } telnet; [edit] user@host#wildcard delete system services *
syntax error.
删除语句时,将从配置中移除语句及其所有从属语句和标识符。
要删除相关配置项目,请 wildcard
用选项发出配置模式命令 delete
并指定语句路径、要用正则表达式汇总的项目和正则表达式,如下所示:
user@host# wildcard delete <statement-path> <identifier> <regular-expression>
使用 wildcard
命令删除相关配置项目时,正则表达式必须是最终语句。
如果匹配 Junos OS 八个以上的相关项目,CLI 只会显示前八个项目。
如何从配置中删除接口
您可以使用以下语法删除从到t1-0/0/0:0
t1-0/0/0:23
范围内的多个 T1 接口:
user@host# wildcard delete interfaces t1-0/0/0:.*
matched: t1-0/0/0:0
matched: t1-0/0/0:1
matched: t1-0/0/0:2
Delete 3 objects? [yes,no] (no) no
如何从配置中删除路由
您可以使用以下语法删除从 172.0.0.0
到 172.255.0.0
范围内的静态路由:
user@host# wildcard delete routing-options static route 172.*
matched: 172.16.0.0/12
matched: 172.16.14.0/24
matched: 172.16.100.0/24
matched: 172.16.128.0/19
matched: 172.16.160.0/24
matched: 172.17.12.0/23
matched: 172.17.24.0/23
matched: 172.17.28.0/23
...
Delete 13 objects? [yes,no] (no)
示例:从设备配置中删除语句
以下示例说明如何删除语句 ospf
,从而有效地在路由器上取消配置 OSPF:
[edit] user@host#set 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#delete protocols ospf
[edit] user@host#show
[edit] user@host#
从当前级别删除所有语句:
[edit] user@host#edit protocols ospf area 0.0.0.0
[edit protocols ospf area 0.0.0.0] user@host#set interface so-0/0/0 hello-interval 5
[edit protocols ospf area 0.0.0.0] user@host#delete
Delete everything under this level? [yes, no]yes
[edit protocols ospf area 0.0.0.0] user@host#show
[edit] user@host#
取消配置特定属性。在此示例中,删除接口速度设置:
[edit] user@host#set interfaces so-3/0/0 speed 100mb
[edit] user@host#show
interfaces { so-3/0/0 { speed 100mb; } } [edit] user@host#delete interfaces so-3/0/0 speed
[edit] user@host#show
interfaces { so-3/0/0; }
在配置中复制语句
如果设备配置中有许多类似的语句,则可以添加一个语句,然后复制该语句。复制语句会复制该语句以及该语句下配置的整个语句层次结构。当您配置许多相同类型的物理或逻辑接口时,复制语句很有用。
要复制配置中的现有语句:
- 使用配置模式
copy
命令:user@host#
copy existing-statement to new-statement
- 复制部分配置后,立即检查新配置的有效性。
- 如果配置无效,请修改复制的部分或原始部分以生成有效的配置。
示例:在配置中复制语句
此示例说明如何通过复制现有 VC 在接口上创建一个虚拟连接 (VC)。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
开始此示例之前,请配置以下初始配置:
[edit interfaces]
user@host# show
at-1/0/0 {
description "PAIX to MAE West"
encapsulation atm-pvc;
unit 61 {
point-to-point;
vci 0.61;
family inet {
address 10.0.1.1/24;
}
}
}
要快速配置此示例的初始配置,请复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改必要的详细信息,以便与网络配置匹配,将此命令复制并粘贴到层次结构级别的 CLI 中 [edit]
,然后进入 commit
配置模式。
set interfaces at-1/0/0 description "PAIX to MAE West" set interfaces at-1/0/0 encapsulation atm-pvc set interfaces at-1/0/0 unit 61 point-to-point set interfaces at-1/0/0 unit 61 vci 0.61 set interfaces at-1/0/0 unit 61 family inet address 10.0.1.1/24
概述
在此说明如何复制语句的示例中,您将添加一个与已配置的虚拟连接非常相似的虚拟连接。
配置
CLI 快速配置
从 [edit interfaces at-1/0/0]
层次结构级别开始。
copy unit 61 to unit 62
set unit 62 vci 0.62
edit unit 62
replace pattern 10.0.1.1 with 10.0.2.1
通过复制配置
逐步过程
要通过复制配置进行配置:
转到
[edit interfaces at-1/0/0]
层次结构级别并复制单元 61。[edit interfaces at-1/0/0] user@host#
copy unit 61 to unit 62
-
查看新配置,了解需要更改什么才能使配置有效。
user@host#
show interfaces at-1/0/0
description "PAIX to MAE West" encapsulation atm-pvc; unit 61 { point-to-point; vci 0.61; family inet { address 10.0.1.1/24; } } unit 62 { point-to-point; vci 0.61; family inet { address 10.0.1.1/24; } } 更改配置使其生效。
在此示例中,您要重新配置虚拟电路标识符 (VCI) 和虚拟路径标识符 (VPI)。
[edit interfaces at-1/0/0] user@host#
set unit 62 vci 0.62
您还希望将新接口的 IP 地址替换为自己的 IP 地址。
[edit interfaces at-1/0/0] user@host#
edit unit 62
user@host#replace pattern 10.0.1.1 with 10.0.2.1
结果
[edit] show interfaces at-1/0/0 { description "PAIX to MAE West" encapsulation atm-pvc; unit 61 { point-to-point; vci 0.61; family inet { address 10.0.1.1/24; } } unit 62 { point-to-point; vci 0.62; family inet { address 10.0.2.1/24; } } }
示例:替换配置
如果需要更改设备的配置,您可以随时使用 delete
命令移除原始配置设置,然后使用命令添加新配置设置 set
。但是,还有其他修改配置的方法可以更高效、更易于使用。
此示例说明如何使用以下配置模式命令更新现有配置:
rename
-重命名现有配置设置,如接口名称。当您向设备添加新接口时,此命令会很有用。copy
-复制配置设置和在此设置下配置的整个语句层次结构。当您配置许多相同类型的物理或逻辑接口时,复制配置语句很有用。replace
- 对配置中的文本模式进行全局更改。例如,如果您始终打错设备上所有接口的描述语句中通用的单词,则可以使用单个命令修复此错误。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在本主题的第一个示例中,您将进行以下配置更改:
创建一个包含打字错误说明的新接口。
从创建的接口复制配置以创建新接口。
重命名您创建的其中一个接口。
修复为创建的接口的描述中键入错误。
在第二个简短的示例中,您可以在略有不同的情况下尝试一些相同的命令。
配置
使用复制、重命名和替换命令修改环路接口配置
逐步过程
如果现有配置使用此示例中使用的任何环路接口单元编号,则必须替换不同未使用的环路接口单元编号。否则,执行这些步骤可能会损坏设备的现有运行状态。
要使用 、 rename
replace
和命令创建和修改环路接口copy
的配置:
-
创建新的环路接口单元编号并包含说明。
描述中的环路拼写错误是有意识的。
[edit] user@host#
set interfaces lo0 unit 100 description "this is a lopbck interface"
-
显示刚刚添加的环路接口的配置。
[edit] user@host#
show interfaces lo0 unit 100
description "this is a lopbck interface";
-
复制刚刚创建的环路接口,包括错误,从单元 100 复制到单元 101。
[edit] user@host#
copy interfaces lo0 unit 100 to unit 101
-
显示环路接口 lo0 单元 100 和 lo0 单元 101 的配置。
[edit] user@host#
show interfaces lo0 unit 100
description "this is a lopbck interface";
[edit] user@host#show interfaces lo0 unit 101
description "this is a lopbck interface";
命令
copy
会复制包括任何子语句的接口,例如description
。 -
将环路接口 lo0 单元 100 重命名为环路接口 lo0 单元 102。
[edit] user@host#
rename interfaces lo0 unit 100 to unit 102
-
显示环路接口 lo0 单元 100 的配置。
[edit] user@host#
show interfaces lo0 unit 100
[edit] user@host#不应看到此命令的任何结果。环路接口 lo0 单元 100 现在已经不见了。命令
rename
将替换新配置指示的配置语句。 -
修复环路接口 lo0 单元 101 和 lo0 单元 102 说明中环 回单词拼写错误。
[edit] user@host#
replace pattern lopbck with loopback
-
显示环路接口 lo0 单元 101 和 lo0 102 的配置,以验证 环路 一词现在是否已拼写正确。
[edit] user@host#
show interfaces lo0 unit 101
description "this is a loopback interface";
[edit] user@host#show interfaces lo0 unit 102
description "this is a loopback interface";
命令
replace
将替换命令指定的所有模式实例,除非以某种方式限制。本主题的下一个示例展示了限制命令效果的replace
一种方法。 -
在配置模式下,使用
rollback
命令将设备配置返回到执行上述步骤之前的状态。[edit] user@host#
rollback
结果
在配置模式下,在执行此示例中的步骤之前,使用 show interfaces lo0 unit 101
and show interfaces lo0 unit 102
命令来确保设备配置处于其状态。
[edit]
user@host: show interfaces lo0 unit 101
[edit]
user@host#
不应看到此命令的任何结果。
[edit] user@host# show interfaces lo0 unit 102 [edit] user@host#
不应看到此命令的任何结果。
比较顶层配置层次结构级别的 copy 命令
逐步过程
上一个示例显示了层级的 copy
[edit interfaces interface-name unit logical-interface-number]
、 rename
和replace
命令。此示例显示了其中一些命令如何在 CLI 配置模式层次结构的顶层发挥作用。
以下示例要求您导航至配置层次结构中的各个级别。有关导航 CLI 的信息,请参阅 在配置模式下使用 CLI 编辑器 。
-
创建以太网接口。
[edit] user@host#
set interfaces et-2/0/0 unit 0 family inet address 192.0.2.2
-
将刚刚创建的接口复制到另一个接口。
[edit] user@host#
copy interfaces et-2/0/0 to et-2/1/0
将此命令
copy
与上一示例中的命令进行比较,其中命令在copy
复制值之前采用关键字unit
:[edit] user@host#
copy interfaces lo0 unit 100 to unit 101
请注意,关键字
interfaces
不会在介词to
之后和要复制的值之前重复。这发生在使用命令的一些顶级语句中copy
。提示:同样,在命令中
rename
,您不会在某些顶级语句中出现新标识符之前重复语句的关键词部分。 -
显示您的配置。
[edit] user@host#
show interfaces
et-2/0/0 { unit 0 { family inet { address 192.0.2.2/32; } } } et-2/1/0 { unit 0 { family inet { address 192.0.2.2/32; } } } -
将 et-2/1/0 的地址替换为其他 IP 地址。
[edit interfaces et-2/1/0 unit 0 family inet] user@host#
replace pattern 192.0.2.2 with 192.0.2.40
请注意,如果只想更改模式的某个特定事件,而非所有出现事件,则在使用命令之前
replace
,必须导航至该特定的层次结构级别。 -
再次显示接口。
[edit] user@host#
show interfaces
et-2/0/0 { unit 0 { family inet { address 192.0.2.2/32; } } } et-2/1/0 { unit 0 { family inet { address 192.0.2.40/32; } } } -
在配置模式下,使用
rollback
命令将设备配置返回到执行上述步骤之前的状态。[edit] user@host#
rollback
结果
在配置模式下,在执行此示例中的步骤之前,使用 show interfaces et-2/0/0
and show interfaces et-2/1/0
命令来确保设备配置处于其状态。
[edit]
user@hostshow interfaces et-2/0/0
[edit]
user@host#
不应看到此命令的任何结果。
[edit]
user@R1# show interfaces et-2/1/0
[edit]
user@host#
不应看到此命令的任何结果。
在设备配置中插入新标识符
配置瞻博网络设备时,您可以按任意顺序输入大多数语句和标识符。无论您输入配置语句的顺序如何,CLI 始终按严格顺序显示配置。但是,在少数情况下,语句的顺序很重要,因为配置语句会创建一个按顺序进行分析的序列。
例如,在路由策略或防火墙过滤器中,您可以定义按顺序分析的术语。此外,在动态 MPLS 中创建命名路径时,您可以在该路径中定义一个中继路由器的有序列表,从第一个传输路由器开始,以最后一个路由器结束。
要修改语句顺序很重要的配置部分,请使用 insert
配置模式命令:
user@host#insert <statement-path> identifier1 (before | after) identifier2
如果未使用命令, insert
而是配置标识符,则标识符将被放置在类似标识符列表的末尾。
示例:在设备配置中插入新标识符
此示例显示了命令的使用 insert
。
虽然使用 set
命令添加的术语会放置在现有术语列表的末尾,但您可以使用 insert
命令按照指定的顺序添加术语。在顺序很重要的情况下,指定语句顺序非常重要,因为配置语句会创建按顺序分析的顺序。
如此示例所示,必须先创建术语(或必须已存在),然后才能与命令一起 insert
使用。术语的参考点也必须存在:例如,将术语 T1 置于术语 T2 之前,T1 和 T2 必须已存在并已填充。 Junos OS 自动移除空词。
要求
在插入术语之前,您必须配置初始策略。要快速配置此示例的初始策略,请复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改必要的详细信息,以便与网络配置匹配,将命令复制并粘贴到层级的 [edit policy-options]
CLI 中,然后从配置模式进入 commit
。
set policy-statement statics term term1 from route-filter 192.168.0.0/16 orlonger set policy-statement statics term term1 from route-filter 224.0.0.0/3 orlonger set policy-statement statics term term1 then reject set policy-statement statics term term2 from protocol direct set policy-statement statics term term2 then reject set policy-statement statics term term3 from protocol static set policy-statement statics term term3 then reject set policy-statement statics term term4 then accept
现在检查以验证是否已正确配置层次结构:
[edit policy-options]
user@host# show
policy-statement statics {
term term1 {
from {
route-filter 192.168.0.0/16 orlonger;
route-filter 224.0.0.0/3 orlonger;
}
then reject;
}
term term2 {
from protocol direct;
then reject;
}
term term3 {
from protocol static;
then reject;
}
term term4 {
then accept;
}
}
概述
要修改语句顺序很重要的配置部分,必须使用 insert
配置模式命令。如果改用 set
命令,则添加的语句或标识符将按顺序位于错误的位置。要按正确顺序获取命令条款,唯一的另一种方法是拆除配置,然后从头开始。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit policy-options] 层次结构级别的 CLI 中,然后进入 commit
配置模式。
[edit] user@host#rename policy-options policy-statement statics term term4 to term term6
[edit] user@host#set policy-options policy-statement statics term term4 from protocol local
[edit] user@host#set policy-options policy-statement statics term term4 then reject
[edit] user@host#set policy-options policy-statement statics term term5 from protocol aggregate
[edit] user@host#set policy-options policy-statement statics term term5 then reject
[edit] user@host#insert policy-options policy-statement statics term term4 after term term3
[edit] user@host#insert policy-options policy-statement statics term term5 after term term4
配置为插入术语
逐步过程
-
确定配置条款所需的顺序。考虑原条款和计划添加的新条款。
在原始配置中,策略命名
statics
为,有四个术语。前三个术语中的每一个都匹配不同的匹配标准,由此产生的匹配项将被拒绝。最后一个术语接受所有其他流量。在此示例中,您需要添加两个术语来消除其他类型的流量。这两个术语都需要在原始配置的最后一个术语之前进行。
将原始术语 4 重命名为术语 6。
[edit] user@host#
rename policy-options policy-statement statics term term4 to term term6
这一步将保留原始的最后一个术语,现在重命名为术语 6,作为最后一个术语。
创建新术语4。
[edit] user@host#
set policy-options policy-statement statics term term4 from protocol local
user@host#set policy-options policy-statement statics term term4 then reject
系统会添加新术语,用于匹配来自本地系统地址的流量,并拒绝它。
创建新术语 5。
[edit] user@host#
set policy-options policy-statement statics term term5 from protocol aggregate
user@host#set policy-options policy-statement statics term term5 then reject
将添加一个新术语,用于匹配来自聚合路由的流量并拒绝它。
在术语 3 后插入术语 4。
[edit] user@host#
insert policy-options policy-statement statics term term4 after term term3
在术语 4 后插入术语 5。
[edit] user@host#
insert policy-options policy-statement statics term term5 after term term4
结果
[edit]
user@host# show policy-options policy-statement statics
term term1 {
from {
route-filter 192.168.0.0/16 orlonger;
route-filter 224.0.0.0/3 orlonger;
}
then reject;
}
term term2 {
from protocol direct;
then reject;
}
term term3 {
from protocol static;
then accept;
}
term term4 {
from protocol local;
then reject;
}
term term5 {
from protocol aggregate;
then reject;
}
term term6 {
then accept;
}
停用和重新激活设备配置中的语句和标识符
在配置中 Junos OS ,您可以停用语句和标识符,以便在发出 commit
命令时它们不会生效。所有停用的语句和标识符都使用标记 inactive
进行标记。它们保留在配置中,但在发出 commit
命令时不会激活。
要停用语句或标识符,请使用 deactivate
配置模式命令:
user@host# deactivate( statement | identifier )
要重新激活语句或标识符,请使用 activate
配置模式命令:
user@host# activate ( statement | identifier )
在这两个命令中statement
identifier
,您指定的和指定的都必须位于当前的层次结构级别。停用语句时,发出命令时 commit
,将忽略该特定语句,并且根本不应用该语句。
要禁用语句,请使用 disable
配置模式命令。
在配置层次结构的某些部分,您可以包含一个 disable
语句来禁用功能。一个例子是通过在[edit interface
interface-name]
层次结构级别包含disable
语句来禁用接口。禁用某个功能时,在您发出 commit
命令时将重新激活,但被视为关闭或管理性禁用功能。
示例:停用和重新激活设备配置中的语句和标识符
此示例显示了一个常见用例, deactivate
其中您使用和 activate
配置模式命令。它涉及配置了平滑路由引擎切换 (GRES) 的双路由引擎、主路由引擎和备份路由引擎。两个路由引擎上的软件都需要升级。通过停用 GRES、更新路由引擎,然后重新激活 GRES,可以轻松实现这一目标。
您也可以使用相同的设置执行类似的升级,只是配置了不间断活动路由 (NSR),而不是 GRES。您需要停用 NSR,然后升级路由引擎,然后重新激活 NSR。
要求
此示例要求使用具有双路由引擎且可升级的设备。
开始此示例之前,请确保您已配置 GRES。
概述
在此示例中,有两个路由引擎。GRES 已配置,需要升级路由引擎。要完成升级,您需要停用 GRES 功能,升级每个路由引擎,然后再次激活 GRES。
配置
配置 GRES 的停用和重新激活
逐步过程
要停用和重新激活用于路由引擎升级的 GRES:
显示已为路由器启用 GRES。
[edit] user@host#
show chassis
redundancy { graceful-switchover; } fpc 2 { pic 0 { tunnel-services { bandwidth 1g; } } }停用 GRES。
[edit] user@host#
deactivate chassis redundancy graceful-switchover
user@host#commit
显示 GRES 已停用。
[edit] user@host#
show chassis
redundancy { inactive: graceful-switchover; } fpc 2 { pic 0 { tunnel-services { bandwidth 1g; } } }-
逐个升级路由引擎。
有关在双路由引擎上升级 Junos OS 的说明,请参阅 在配备冗余路由引擎的设备上安装软件包。
重新激活 GRES。
[edit] user@host#
activate chassis redundancy graceful-switchover
user@host#commit
结果
验证是否再次激活 GRES 功能。
[edit]
user@host# show chassis
redundancy {
graceful-switchover;
}
fpc 2 {
pic 0 {
tunnel-services {
bandwidth 1g;
}
}
}
如何对设备配置进行全局更改
您可以使用配置模式命令对设备配置 replace
中的变量和标识符进行全局更改。此命令将配置中的模式替换为其他模式。例如,当 PIC 移动到路由器中的另一个插槽时,您可以使用此命令查找并替换某个接口名称的所有出现项。
user@host# replace pattern pattern1 with pattern2 <upto n>
选项 pattern
pattern1
是文本字符串或正则表达式,用于定义您要在配置中替换的标识符和值。
选项 pattern2
是文本字符串或正则表达式,用于替换位于中的 pattern1
标识符和值。
CLI 使用标准 UNIX 样式正则表达式语法(如 POSIX 1003.2 中定义)。如果正则表达式包含空格、运算符或通配符字符,请将表达式括在引号内。支持贪婪的资格赛(尽可能匹配)。不支持懒惰资格赛(尽可能少匹配)。
选项 upto
n
用于指定替换的对象数。的值 n
控制配置中替换的对象总数(而不是模式发生的总数)。首先替换同一层级(同级)的对象。在给定对象中出现多次模式被视为单个替换。例如,如果配置包含 010101
文本字符串,命令 replace pattern 01 with pattern 02 upto 2
将 010101
020202
替换为(而不是 020201
)。更换为010101
020202
一次更换 (n
= 1
),而不是三次单独的更换 (n
=3
)。
如果未指定 upto
选项,将替换配置中匹配 pattern1
的所有标识符和值。
命令 replace
可在任何层级的配置模式下使用。所有匹配项均区分大小写。
用于命令的公共 replace
正则表达式
操作人员 |
功能 |
---|---|
|
指示匹配可以是管道两侧的两个项之一。 |
|
在表达式的开头使用,表示匹配应从何处开始。 |
|
在表达式末尾使用的术语表示,术语必须与字符的 |
|
指定要匹配的字母或数字范围。要分隔范围的开头和结尾,请使用连字符 ( - )。 |
|
指定要匹配的一组术语。以编号变量存储。用于背部参考 |
|
表示 0 个或多个术语。 |
|
表示一个或多个术语。 |
|
表示除空格 (“ ” ) 以外的任何字符。 |
|
反斜杠会转义特殊字符,以抑制其特殊意义。例如,\. |
|
与该组匹配的 n回引用。 |
|
与整个匹配项匹配的回引用。 |
下表列出一些替换示例。
命令 |
结果 |
---|---|
|
匹配: 成果: |
|
匹配: 成果: |
|
匹配: 成果: |
|
匹配: 成果: |
示例:如何在设备配置中使用全局替换 — \n 返回参考
此示例说明如何使用背面引用来替换模式。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
开始之前,请配置以下各项:
[edit]
user@host# show interfaces
xe-0/0/0 {
unit 0;
}
fe-3/0/1 {
vlan-tagging;
unit 0 {
description "inet6 configuration. IP: 2000::c0a8::1bf5";
vlan-id 100;
family inet {
address 17.10.1.1/24;
}
family inet6 {
address 2000::c0a8:1bf5/3;
}
}
}
要快速配置此初始配置,请复制以下命令并将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 CLI 中 [edit]
:
set interfaces xe-0/0/0 unit 0
set interfaces fe-3/0/1 vlan-tagging
set interfaces fe-3/0/1 unit 0 description "inet6 configuration IP: 2000::c0a8::1bf5"
set interfaces fe-3/0/1 unit 0 vlan-id 100
set interfaces fe-3/0/1 unit 0 family inet address 17.10.1.1/24
set interfaces fe-3/0/1 unit 0 family inet6 address 2000::c0a8:1bf5/3
概述
正则表达式最有用的功能之一是背面参考。通过回配,可以方便地识别字符串内的重复字符或子字符串。找到模式后,就可以重复它,而不必再次编写。您可将先前捕获的模式指为正 \#
(其中 #
数字表示您希望匹配该模式的次数)。
您可以使用回配来调用或查找数据,并将其替换为其他数据。这样,您可以使用一个替换命令重新格式化大量数据,从而节省手动查找和替换模式所需的时间。
配置
在命令中使用回参考配置替换项
逐步过程
要使用背面参考替换配置中的 Junos OS 模式:
replace
使用命令。[edit] user@host#
replace pattern pattern1 with pattern2
在本案例中,我们要用
:1bf5
1bf5
.[edit] user@host#
replace pattern "(.*):1bf5" with "\11bf5"
请注意背面参考 (\1),它表示只应搜索并替换该模式一次。
结果
以下是由此产生的配置:
[edit]
user@host# show interfaces
xe-0/0/0 {
unit 0;
}
fe-3/0/1 {
vlan-tagging;
unit 0 {
description "inet6 configuration. IP: 2000::c0a8:1bf5";
vlan-id 100;
family inet {
address 17.10.1.1/24;
}
family inet6 {
address 2000::c0a8:1bf5/3;
}
}
}
在此示例中,该模式 2000::c0a8::1bf5
将替换为 2000::c0a8:1bf5
一次。
示例:设备配置中的全局替换 — 替换接口名称
此示例说明如何使用命令替换配置 replace
中的接口名称全局。
使用 replace
命令可以更快、更好地更改配置。例如,可能会将 PIC 移动到路由器中的另一个插槽中,这会更改接口名称。使用一个命令,即可更新整个配置。或者,您可能希望使用其他类似配置(例如,类似的接口)快速扩展配置。
通过组合 copy
使用和 replace
命令,您可以向配置添加内容,然后替换新复制的配置的某些方面。命令 replace
适用于正则表达式。正则表达式快速、灵活且无处不在。您可以设计出可能需要搜索的任何模式,而且大多数编程语言都支持正则表达式。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
开始之前,在路由器上配置以下层次结构。要快速配置此层次结构,请参阅 CLI 快速配置 。
user@host#show interfaces
so-0/0/0 { dce; } user@host#show protocols
ospf { area 0.0.0.0 { interface so-0/0/0.0 { hello-interval 5; } } }
概述
此示例说明如何使用命令替换配置 replace
中的接口名称全局。这是一个简单的例子。
之前的配置是此配置更新的起点。在此示例过程中,您可以使用一个命令在整个配置中更改初始接口的名称。
配置
CLI 快速配置
要快速配置此示例的初始配置,请复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改必要的详细信息,以便与网络配置匹配,将这些命令复制并粘贴到层次结构级别的 CLI 中 [edit]
,然后从配置模式进入 commit
。:
set interfaces so-0/0/0 dce set protocols ospf area 0.0.0.0 interface so-0/0/0.0 hello-interval 5
配置接口名称更改
逐步过程
要更改接口名称:
确保您位于配置模式层次结构的顶层。
user@host#
top
-
so-1/1/0
替换为so-0/0/0
使用replace
关键字的pattern
命令。user@host#
replace pattern so-0/0/0 with so-1/1/0
结果
进行所需更改后,使用 show interfaces
和 show protocols
配置模式命令验证配置。
[edit] user@host#show interfaces
so-1/1/0 { dce; } user@host#show protocols
ospf { area 0.0.0.0 { interface so-1/1/0.0 { hello-interval 5; } } }
确认配置正确后,输入 commit
命令。
示例:设备配置中的全局替换 — 上一选项
考虑中所示的 图 1层次结构。文本字符串 010101
将出现在三个位置:说明部分ge-0/0/0
ge-0/0/0.0
、 和fe-0/0/1
。这三个实例是三个对象。以下示例说明了如何使用选项在 upto
设备配置中执行替换:

upto 2
命令中的replace
选项将01
02
转换为两个对象实例。将首先替换主接口 ge-0/0/0
下的对象( fe-0/0/1
因为这些是层级中的同级对象)。受此 upto 2
限制, replace
命令会替换层次结构中的第一个实例和第二个实例(同级实例)中的模式,但不会替换第三个实例(第一个实例的子实例)。
user@host#show interfaces
ge-0/0/0 { description "mkt 010101"; #First instance in the hierarchy unit 0 { description "mkt 010101"; #Third instance in the hierarchy (child of the first instance) } } fe-0/0/1 { description "mkt 010101"; #second instance in the hierarchy (sibling of the first instance) unit 0 { family inet { address 200.200.20.2/24; } } } [edit] user@host#replace pattern 01 with 02 upto 2
[edit] user@host#commit
commit complete
[edit]
user@host# show interfaces
ge-0/0/0 {
description "mkt 020202"; #First instance in the hierarchy
unit 0 {
description "mkt 010101"; #Third instance in the hierarchy (child of the first
instance)
}
}
fe-0/0/1 {
description "mkt 020202"; #second instance in the hierarchy (sibling of the first
instance)
unit 0 {
family inet {
address 200.200.20.2/24;
}
}
}
在设备配置中添加注释
您可以在设备配置中包含注释,以描述配置中的任何语句。您可以在 CLI 中通过编辑 ASCII 配置文件,以交互方式添加注释。
配置接口时,可以通过在层次结构级别包含 description
语句来添加有关接口的 [edit interfaces
interface-name
]
注释。您包括的任何注释都会出现在命令输出中show interfaces
。
在 CLI 中添加注释
在配置模式下添加注释时,注释与当前级别的语句相关联。每个语句都可以有一个与之关联的单行注释。语句必须存在,才能将注释与语句关联。注释放置在语句之前的一行上。
要向配置添加注释,请使用 annotate
配置模式命令:
user@host# annotate statement "comment-string
"
statement
是附加注释的配置语句;它必须处于当前的层级如果指定 statement
注释已存在,则将其删除,并替换为新注释。
comment-string
是备注的文本。注释文本可以是任意长度,您必须在单行中键入。如果备注包含空格,则必须用引号括起来。在注释字符串中,您可以包括注释分隔符 /* */
或 #
。如果未指定任何注释,则注释字符串将括在 /* */
注释分隔符内。
要删除现有注释,请指定空注释字符串:
user@host# annotate statement ""
如果您使用命令添加注释 annotate
,则可以通过输入 show 配置模式命令或 show configuration
操作模式命令来查看配置中的注释。
Junos OS 支持配置层次结构中最高到最后一个级别的注释,包括 oneliners。但是,不支持对 oneliner 的各个部分(oneliner 中的子语句或标识符)进行注释。例如,在以下示例配置层次结构中,最高支持父层次结构的 level 1
注释,但不支持 metric
子语句:
[edit protocols] isis { interface ge-0/0/0.0 { level 1 metric 10; } } }
在文件中添加注释
编辑 ASCII 配置文件并添加注释时,可以是一行或多行,并且必须位于与之关联的语句之前。如果将注释放在文件中的其他位置(例如语句后的同一行或语句后的单独一行上),则使用 load
命令在 CLI 中打开配置时,这些注释将被移除。
以下配置示例摘录说明了如何在配置文件中放置以及如何不将注释置入配置文件中:
/* This comment goes with routing-options */ routing-options { /* This comment goes with routing-options traceoptions */ traceoptions { /* This comment goes with routing-options traceoptions tracefile */ tracefile rpd size 1m files 10; /* This comment goes with routing-options traceoptions traceflag task */ traceflag task; /* This comment goes with routing-options traceoptions traceflag general */ traceflag general; } autonomous-system 10458; /* This comment is dropped */ } routing-options { rib-groups { ifrg { import-rib [ inet.0 inet.2 ]; /* A comment here is dropped */ } dvmrp-rib { import-rib inet.2; export-rib inet.2; /* A comment here is dropped */ } /* A comment here is dropped */ } /* A comment here is dropped */ }
当直接在配置文件中包含注释时,可以通过以下方式设置注释格式:
以 a
/*
开始评论,以*/
. 注释文本可以位于单行上,也可以跨越多行。以 a
#
开始评论,以新行结束(回车)。
示例:使用 CLI 在设备配置中包括注释
为设备配置添加注释,使配置文件的可读性更高,用户更容易理解。您可以使用语句在配置 annotate
时包括注释。在此示例中,通过使用 CLI 对现有配置添加注释:
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
添加注释之前,必须在路由器上配置以下层次结构。
要快速配置此示例的初始配置,请复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改必要的详细信息,以便与网络配置匹配,将此命令复制并粘贴到层级的 [edit]
CLI 中,然后从配置模式进入 commit
。
set protocols ospf area 0.0.0.0 interface so-0/0/0.0 hello-interval 5
现在验证是否已配置此层次结构。
user@host# show protocols
ospf {
area 0.0.0.0 {
interface so-0/0/0 {
hello-interval 5;
}
}
}
概述
使用 CLI 添加注释时,请在配置模式下使用 annotate
语句进行添加。您添加的每个注释都与当前级别的一个语句相关联。每个语句都可以有一个与之关联的单行注释。
要配置 annotate
语句,请移动到要与之关联的语句级别。要查看注释,请转至配置层次结构的顶部,然后使用 show
命令。
配置
CLI 快速配置
要快速配置此示例的注释,请从层级开始,复制以下命令,将其粘贴到文本文件中,删除所有换行符并更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 CLI 中 [edit]
,然后从配置模式进入 commit
。
edit protocols ospf
annotate area 0.0.0.0 "Backbone area configuration added June 15, 2018"
edit area 0.0.0.0
annotate interface so-0/0/0.0 "Interface from router sj1 to router sj2"
请注意,当您对层次结构的不同部分进行注释时,命令会向下移动。
在 CLI 配置模式下包括注释
逐步过程
此过程假定您已经配置了初始配置。
要为配置添加注释:
移动到需要添加注释的第一个层次结构级别。
[edit] user@host#
edit protocols ospf
使用
annotate
语句向area
配置语句添加注释。[edit protocols ospf] user@host#
annotate area 0.0.0.0 "Backbone area configuration added June 15, 1998"
下移一个级别到
interface
配置语句。[edit protocols ospf] user@host#
edit area 0.0.0.0
-
使用
annotate
语句向接口so-0/0/0.0
添加注释。[edit protocols ospf area 0.0.0.0] user@host#
annotate interface so-0/0/0.0 "Interface from router sj1 to router sj2"
结果
移动到层次结构的顶部,然后使用 show
命令查看您添加的注释。注释位于与之关联的语句之前。
[edit]
user@host# show protocols
ospf {
/* Backbone area configuration added June 15, 2018 */
area 0.0.0.0 {
/* Interface from router sj1 to router sj2 */
interface so-0/0/0.0 {
hello-interval 5;
}
}
}
确认配置正确后,输入 commit
命令。
示例:将通配符命令与范围选项一起使用
如果需要更改设备的配置,您可以随时使用 delete
命令移除原始配置设置,然后使用命令添加新配置设置 set
。但是,还有其他修改配置的方法可以更高效、更易于使用。
此示例说明如何使用通配符命令以及激活、停用、删除、保护、设置、显示和取消保护配置命令中的范围。
通配符命令无法创建配置层次结构。您可以使用它来修改现有语句。尝试在空层次结构上设置参数(如停用)时,预计表单 warning: statement not found
的 CLI 错误。
要求
设备上运行的 Junos OS 12.1 或更高版本。
概述
使用带有通配符命令的范围选项,您可以指定激活、停用、删除、保护、设置、显示和取消保护命令中的范围。您可以使用范围来指定一系列接口、逻辑单元、VLAN 和其他编号元素。通配符范围选项可将您输入的命令扩展为多个命令,每个命令都与范围内的一项相对应。
使用通配符范围选项,您可以使用一组命令配置多个配置语句,而不是分别配置每个配置语句。例如,要使用不同的端口号配置 24 千兆以太网接口,您可以使用单个通配符范围集命令,而不是 24 个单独的接口集命令。
同样,要停用一组 30 个逻辑接口,您可以使用通配符范围停用命令,而不是分别停用每个逻辑接口。
配置
- 将通配符命令与范围语句一起用于各种配置任务。
- 使用 Range 选项为 Configuration 语句配置一系列命名标识符
- 在语法中指定多个范围
- 以语法指定范围和唯一数字
- 从一个范围中排除某些值
- 使用步数指定范围
- 使用通配符删除策略 p1-p10
将通配符命令与范围语句一起用于各种配置任务。
逐步过程
- 您可以使用通配符范围以及活动、停用、删除、保护、设置、显示和取消保护配置命令。
[edit] user@host#
wildcard range ? Possible completions: activate Remove the inactive tag from a statement annotate Annotate the statement with a comment deactivate Add the inactive tag to a statement delete Delete a data element protect Protect the statement set Set a parameter show Show a parameter unprotect Unprotect the statement
-
语句
wildcard
可以使用完整的配置层次结构来限定。当停在配置层次结构中时,通配符命令相对于该层次结构支持的选项。[edit] user@host#
wildcard range set interfaces ? Possible completions: <interface-name> Interface name + apply-groups Groups from which to inherit configuration data + apply-groups-except Don't inherit configuration data from these groups > interface-range Interface ranges configuration > interface-set Logical interface set configuration lo0 Interface name > stacked-interface-set Stacked interface set configuration > traceoptions Interface trace options xe-0/0/0:0 Interface name xe-0/0/0:1 Interface name
user@host# edit interfaces [edit interfaces]wildcard range set ? Possible completions: <interface-name> Interface name + apply-groups Groups from which to inherit configuration data + apply-groups-except Don't inherit configuration data from these groups > interface-range Interface ranges configuration > interface-set Logical interface set configuration lo0 Interface name > stacked-interface-set Stacked interface set configuration > traceoptions Interface trace options xe-0/0/0:0 Interface name xe-0/0/0:1 Interface name
在第一种情况下,使用通配符语句指定接口层次结构的完整路径。第二种情况是,用户将停在接口层次结构中。使用任一方法时,支持的选项都相同。
使用 Range 选项为 Configuration 语句配置一系列命名标识符
逐步过程
要配置具有不同端口号(0 到 23)的相同接口类型,请使用以下格式为端口号指定范围。
-
[edit] user@host# wildcard range set interfaces ge-0/0/[0-23] unit 0 family vpls
-
显示结果。范围通配符范围扩展到 24 个不同的集命令,以配置端口号范围为 0 到 23 的接口。在这种情况下,创建接口是为了添加
vpls
协议家族。如果接口已定义,则只需添加家族。root@R1# show | compare [edit interfaces] + ge-0/0/0 { + unit 0 { + family vpls; + } + } + ge-0/0/1 { + unit 0 { + family vpls; + } + } + ge-0/0/2 { + unit 0 { + family vpls; + } + } . . . + ge-0/0/23 { + unit 0 { + family vpls; + }
在语法中指定多个范围
逐步过程
您可以在通配符范围命令中指定多个范围。每个范围都必须用逗号分隔。您还可以有重叠的范围。
对于其余示例,请创建一个包含 10 个策略语句的配置临时副本。拥有这些语句可避免在尝试操作层次结构的空部分的属性时报告的 CLI 错误。
[edit] user@device# set policy-options policy-statement p1 then reject set policy-options policy-statement p10 then reject set policy-options policy-statement p2 then reject set policy-options policy-statement p3 then reject set policy-options policy-statement p4 then reject set policy-options policy-statement p5 then reject set policy-options policy-statement p6 then reject set policy-options policy-statement p7 then reject set policy-options policy-statement p8 then reject set policy-options policy-statement p9 then reject [edit] user@device# save temp Wrote 254 lines of configuration to 'temp'
- 要指定语法中的多个范围,请为每个范围添加最小和最大值,用逗号隔开。
[edit] user@host# wildcard range deactivate policy-options policy-statement p[1-3,5-7,6-9]
-
显示结果。通配符范围扩展,将
deactivate
语句添加到名称与指定范围匹配的策略中。请注意,候选配置的更改列表中没有p4p10出现。注:如果配置中指定的策略名称不存在,将返回错误。这是因为您不能将停用语句添加到配置层次结构的空白部分。
[edit] show | compare [edit policy-options] ! inactive: policy-statement p1 { ... } ! inactive: policy-statement p2 { ... } ! inactive: policy-statement p3 { ... } ! inactive: policy-statement p5 { ... } ! inactive: policy-statement p6 { ... } ! inactive: policy-statement p7 { ... } ! inactive: policy-statement p8 { ... } ! inactive: policy-statement p9 { ... }
以语法指定范围和唯一数字
逐步过程
您可以在通配符范围命令的语法中指定范围和唯一数字的组合。
-
重新加载 临时配置。
[edit] user@host# load override temp load complete
- 要指定范围和唯一编号,请用逗号分隔。在此示例中,10 作为唯一编号添加到一系列范围中。
[edit] user@host# wildcard range deactivate policy-options policy-statement p[1-3,5,7,10]
-
显示结果。通配符范围扩展后,将
deactivate
语句添加到名称与指定范围匹配的策略中,并添加到唯一编号。因此, p10 在此示例中,策略也将停用。注:如果配置中指定的策略名称不存在,将返回错误。这是因为您不能将停用语句添加到空的配置层次结构中。
[edit] user@host# show | compare [edit policy-options] ! inactive: policy-statement p1 { ... } ! inactive: policy-statement p10 { ... } ! inactive: policy-statement p2 { ... } ! inactive: policy-statement p3 { ... } ! inactive: policy-statement p5 { ... } ! inactive: policy-statement p7 { ... }
从一个范围中排除某些值
逐步过程
您可以通过标记数字或使用感叹号排除的数字范围来排除范围中的某些值。
-
重新加载 临时配置。
[edit] user@host# load override temp load complete
- 要从一个范围中排除某些值,请添加要排除的部分!语法中的一部分。
[edit] user@host# wildcard range deactivate policy-options policy-statement p[1-5,!3-4]
-
显示结果。通配符范围扩展,将
deactivate
语句添加到名称与指定范围匹配的策略中。请注意,对候选配置的修改列表中没有策略 p3 和 p4 。它们已被排除在通配符范围之外。注:如果配置中指定的策略名称不存在,将返回错误。这是因为您不能将停用语句添加到空的配置层次结构中。
[edit] user@host# show | compare [edit policy-options] ! inactive: policy-statement p1 { ... } ! inactive: policy-statement p2 { ... } ! inactive: policy-statement p5 { ... }
使用步数指定范围
逐步过程
您可以提供一个步数,以在此范围内保持恒定的间隔。步骤值对第一个匹配项进行计数,然后将后续匹配项跳过到指定的步进值。
-
重新加载 临时配置。
[edit] user@host# load override temp load complete
- 要提供步骤,请将 step 值包含在语法前面以正斜杠 (/) 开头。在这里,我们指定 1-10 的范围,使用 2 的步进值在每个匹配之间跳过 1 个数字。效果是跳过所有偶数匹配的匹配,因为我们首先匹配奇数 (1)。
[edit] user@host# wildcard range deactivate policy-options policy-statement p[1-10/2]
-
显示结果。通配符范围扩大,以将
deactivate
语句添加到每个其他匹配语句中,从第一个匹配开始。注:如果配置中指定的策略名称不存在,将返回错误。这是因为您不能将停用语句添加到空的配置层次结构中。
[edit] user@host# show | compare [edit policy-options] ! inactive: policy-statement p1 { ... } ! inactive: policy-statement p3 { ... } ! inactive: policy-statement p5 { ... } ! inactive: policy-statement p7 { ... } ! inactive: policy-statement p9 { ... }
为了更好地说明步骤功能,将恢复临时配置并重复通配符命令,这次步骤值为 4。现在,每次初始匹配后都会跳过 3 个条目。
[edit] user@host# load override temp load complete user@host## wildcard range deactivate policy-options policy-statement p[1-10/4] \
-
显示结果。通配符范围扩大,以将
deactivate
语句添加到每四个匹配语句一次(从第一个匹配开始)。[edit] user@host# show | compare [edit policy-options] ! inactive: policy-statement p1 { ... } ! inactive: policy-statement p5 { ... } ! inactive: policy-statement p9 { ... }
使用通配符删除策略 p1-p10
逐步过程
删除为测试通配符功能而添加的临时策略。
- 将
delete
语句与通配符范围语句一起用于删除策略p10p1。[edit] user@host# wildcard range delete policy-options policy-statement p[1-10]
-
显示结果。我们的
policy-options
节仅 p1 包含通过 p10。这将导致配置层次结构为空policy-options
。[edit] user@host# show policy-options