修改设备的配置
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]
另请参阅
如何修改瞻博网络设备配置
要配置瞻博网络设备或修改现有配置,请使用 edit
和 set
命令向配置添加语句。对于每个语句层次结构,您都会创建从顶级语句开始的层次结构。然后,您可以继续创建层次结构,其中的语句在层次结构中逐渐降低。
要修改层次结构,请使用两个配置模式命令。根据要完成的任务选择相关命令:
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 集中器 (FPC) 上、第一个 PIC 位置和物理接口卡 (PIC) 上第一个端口上的 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;
}
}
}
要为此示例快速配置初始配置,请复制以下命令,将其粘贴到文本文件中,删除任何换行符并更改与网络配置匹配所需的任何详细信息,将此命令复制并粘贴到层次结构级别的 [edit]
CLI 中,然后进入 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
—全局更改配置中的文本模式。例如,如果您在设备上的所有接口的描述语句中始终误传通用的单词,则可以通过单个命令来修复此错误。
要求
配置此示例之前,无需设备初始化以外的特殊配置。
概述
在本主题的第一个示例中,您将进行以下配置更改:
创建包含键入错误的说明的新接口。
从您创建的接口复制配置以创建新接口。
重命名您创建的其中一个接口。
修复您创建的接口的说明中的键入错误。
在第二个更短的示例中,您会在略有不同的情况下试用一些相同的命令。
配置
使用文案、重命名和替换命令修改环路接口配置
逐步过程
如果您的现有配置使用此示例中使用的任何环路接口单元编号,则必须替换不同未使用的环路接口单元编号。否则,采取这些步骤可能会损坏设备的现有运行状态。
要使用 copy
rename
、 和 replace
命令创建和修改环路接口的配置:
-
创建新的环路接口单元号并包括说明。
描述中回传拼写中的错误是故意的。
[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
和 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
和 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 自动删除空术语。
要求
插入术语之前,必须配置初始策略。要为此示例快速配置初始策略,请复制以下命令,将其粘贴到文本文件中,删除任何换行符并更改与网络配置匹配所需的任何详细信息,将命令复制并粘贴到层次结构级别的 CLI 中 [edit policy-options]
,然后从配置模式进入 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
命令时,该功能会重新激活,但将其视为已关闭或以管理方式禁用。
示例:停用和重新激活设备配置中的语句和标识符
此示例显示了使用和activate
配置模式命令的deactivate
常见用例。它涉及两个路由引擎(主路由引擎和备份路由引擎),它们已配置平滑路由引擎切换 (GRES)。两个路由引擎上的软件都需要升级。这可以通过停用 GRES、更新路由引擎然后重新激活 GRES 轻松实现。
您还可以使用相同的设置执行类似的升级,但不使用 GRES 配置不间断活动路由 (NSR) 除外。您需要停用 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 个或更多术语。 |
|
表示一个或多个术语。 |
|
表示空间(“”)除外的任何字符。 |
|
反斜杠会逃脱特殊人物的压制,从而抑制其特殊含义。例如 \.匹配项 |
|
与 nth 组匹配的回提。 |
|
与整场比赛匹配的后参考。 |
下表列出了一些替换示例。
命令 |
结果 |
---|---|
|
匹配: 成果: |
|
匹配: 成果: |
|
匹配: 成果: |
|
匹配: 成果: |
示例:如何在设备配置中使用全局更换 — \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 可能会移动到路由器中的另一个插槽,而路由器会更改接口名称。使用一个命令,您可以更新整个配置。或者,您可能需要使用其他类似配置(例如类似接口)快速扩展配置。
通过使用和replace
命令的copy
组合,您可以添加到配置,然后替换新复制配置的某些方面。命令 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-0/0/0
为so-1/1/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
选项在设备配置中执行更换:

命令中的replace
选项可转换02
01
为两个upto 2
对象实例。主接口 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 配置文件。
配置接口时,可通过在[edit interfaces
interface-name
]
层次结构级别上包括description
语句来添加有关接口的评论。您包括的任何注释都显示在命令的输出中 show interfaces
。.
在 CLI 中添加备注
在配置模式下添加注释时,它们与当前级别的语句相关联。每个语句都可以有一个与之关联的单行评论。在将评论与语句相关联之前,该语句必须存在。评论放在声明之前的行中。
要向配置添加注释,请使用 annotate
配置模式命令:
user@host# annotate statement "comment-string
"
statement
是您将评论附加到的配置语句;它必须处于当前层次结构级别。如果已存在对指定 statement
评论的评论,则该评论将被删除并替换为新评论。
comment-string
是评论文本。评论文本可以是任何长度,您必须在单行中键入。如果评论中包含空格,则必须用引号将其括起来。在评论字符串中,您可以包括评论划定者 /* */
或 #
。如果您未指定任何,则评论字符串中包含 /* */
评论划定人。
要删除现有评论,请指定空评论字符串:
user@host# annotate statement ""
如果使用 命令添加注释 annotate
,可通过输入 show configuration mode 命令或操作模式命令来查看配置中的 show configuration
注释。
Junos OS 支持最多配置层次结构中最后一个级别的注释,包括单行线。但是,不支持注释单个衬里内的部件(儿童语句或单行线内的标识符)。例如,在以下示例配置层次结构中,最多 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 */ }
在配置文件中直接包含注释时,可通过以下方式格式化评论:
开始评论,
/*
并结束它与一个*/
。评论文本可以在单行中,也可以跨越多个行。从评论
#
开始,然后以新线路结束(回传马车)。
示例:使用 CLI 在设备配置中包含注释
在设备配置中添加注释使配置文件可读且更容易被用户理解。使用 语句配置 annotate
时,您可以包含注释。在此示例中,将 CLI 用于现有配置,从而添加备注:
要求
配置此示例之前,无需设备初始化以外的特殊配置。
添加评论之前,必须在路由器上配置以下层次结构。
要为此示例快速配置初始配置,请复制以下命令,将其粘贴到文本文件中,删除任何换行符并更改与网络配置匹配所需的任何详细信息,将此命令复制并粘贴到层级的 CLI 中 [edit]
,然后从配置模式进入 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
命令。