开始:CLI 快速浏览
以下主题可帮助您(网络管理员)开始使用 Junos OS CLI 执行配置更改、在操作模式和配置模式之间切换、创建用户帐户和执行一些基本命令。
如果需要 Junos OS 的基本介绍,请参阅 Junos OS 入门指南。
有关更深入的信息以及如何将 Junos OS 用于瞻博网络设备,请参阅 Junos OS 概述。
本 Junos OS CLI 指南假定您熟悉 Junos OS 概念和操作原则。
命令行界面入门
本主题介绍如何启动 Junos OS CLI、查看命令层次结构和进行细微的配置更改。
开始之前,请确保设备硬件已设置并 Junos OS 已安装。您必须与设备建立直接控制台连接,或者使用 SSH 或 Telnet 进行网络访问。如果未设置设备,请遵循设备提供的安装说明,然后继续。
要登录设备并启动 CLI:
如果您是第一次在设备上使用 root 帐户,请记住,设备随附的 root 不需要密码。第一次提交配置时,必须设置 root 密码。不允许通过 telnet 会话进行 root 访问。要通过 SSH 连接启用 root 访问,必须配置语句 system services ssh root-login allow
。
CLI 命令可能因平台和软件版本而异。CLI 包括多种获取有关可用命令的帮助的方法。本节演示了获取帮助的一些示例:
-
键入
?
以显示操作模式下可用的顶级命令。root@> ? Possible completions: clear Clear information in the system configure Manipulate software configuration information diagnose Invoke diagnose script file Perform file operations help Provide help information monitor Show real-time debugging information mtrace Trace multicast path from source to receiver ping Ping remote target quit Exit the management session request Make system-level requests restart Restart software process set Set CLI properties, date/time, craft interface message show Show system information ssh Start secure shell on another host start Start shell telnet Telnet to another host test Perform diagnostic debugging traceroute Trace route to remote host
-
键入
file ?
以显示命令的所有可能补全file
。root@> file ? Possible completions: <[Enter]> Execute this command archive Archives files from the system checksum Calculate file checksum compare Compare files copy Copy files (local or remote) delete Delete files from the system list List file information rename Rename files show Show file contents source-address Local address to use in originating the connection | Pipe through a command
-
键入
file archive ?
以显示命令的所有可能补全file archive
。root@> file archive ? Possible completions: compress Compresses the archived file using GNU gzip (.tgz) destination Name of created archive (URL, local, remote, or floppy) source Path of directory to archive
在操作模式和配置模式之间切换
监控和配置正在运行 Junos OS的设备时,可能需要在模式之间切换。在操作模式和配置模式之间切换时,命令提示符也会发生变化。操作模式提示符为右尖括号 (>
)。配置模式提示符为井号 (#
)。
在操作模式和配置模式之间切换:
使用键盘序列导航和编辑 CLI
您可以在 CLI 中使用 Junos OS 键盘序列来导航和编辑命令行。您还可以使用键盘序列滚动浏览最近执行的命令列表。下表列出了一些 CLI 键盘序列。它们与 Emacs 中使用的相同。
键盘序列 |
行动 |
---|---|
Ctrl+b |
将光标向后移动一个字符。 |
Esc+b 或 Alt+b |
将光标向后移动一个单词。 |
Ctrl+f |
将光标向前移动一个字符。 |
Esc+f 或 Alt+f |
将光标向前移动一个单词。 |
Ctrl+a |
将光标移动到命令行的开头。 |
Ctrl+e |
将光标移动到命令行的末尾。 |
Ctrl+h、Delete、 或 Backspace |
删除光标前的字符。 |
Ctrl+d |
删除光标位置的字符。 |
Ctrl+k |
删除从光标到命令行末尾的所有字符。 |
Ctrl+u 或 Ctrl+x |
删除命令行中的所有字符。 |
Ctrl+w、Esc+Backspace、 或 Alt+Backspace |
删除光标前的单词。 |
Esc+d 或 Alt+d |
删除光标后的单词。 |
Ctrl+y |
在光标位置插入最近删除的文本。 |
Ctrl+l |
重绘当前行。 |
Ctrl+p |
向后滚动,浏览最近执行的命令列表。 |
Ctrl+n |
向前滚动,浏览最近执行的命令列表。 |
Ctrl+r |
按相反顺序逐步搜索 CLI 历史记录,查找与搜索字符串匹配的行。 |
Esc+/ 或 Alt+/ |
搜索 CLI 历史记录中以当前单词为前缀的单词。 |
Esc+。或 Alt+。 |
向后滚动,浏览命令行中最近输入的单词列表。 |
Esc+number sequence 或 Alt+number sequence |
指定执行键盘序列的次数。 |
在瞻博网络设备上配置用户帐户
本主题介绍如何使用 root 帐户登录瞻博网络设备并配置新用户帐户。您可以配置供自己使用的帐户,也可以创建测试帐户。
在设备上配置新用户帐户:
您已成功使用 CLI 查看设备状态并执行简单的配置更改。
有关配置设备时要发出的命令的完整信息(包括示例),请参阅 Junos OS 配置指南。
在配置模式下使用 CLI 编辑器
本主题介绍可用于在 CLI 编辑器中进入配置模式的基本命令。本主题还介绍了用于在配置层次结构中导航、获取帮助以及提交或恢复在配置会话期间进行的更改的命令。
任务 |
命令/语句 |
例子 |
---|---|---|
编辑您的配置 | ||
进入配置模式。 启动 CLI 时,设备处于操作模式。您必须以显式方式进入配置模式。这样做时,CLI 提示从更改为 |
configure |
user@host> [edit] user@host# |
创建语句层次结构。 您可以使用 |
edit hierarchy-level value |
[edit]
user@host# [edit security zones security-zone myzone] user@host# |
创建语句层次结构并设置标识符值。 命令 |
set hierarchy-level value |
[edit]
user@host# [edit] user@host# |
在层次结构中导航 | ||
向下导航至现有层次结构级别。 |
edit hierarchy-level |
[edit]
user@host# [edit security zones] user@host# |
在层次结构中向上导航。 |
up |
[edit security zones]
user@host# [edit security] user@host# |
导航至层次结构的顶部。 |
top |
[edit security zones]
user@host# [edit] user@host# |
提交或恢复更改 | ||
提交您的配置。 |
commit |
[edit]
user@host# commit complete |
从当前会话回滚更改。
|
rollback |
[edit]
user@host# load complete |
退出配置模式 | ||
提交配置,然后退出配置模式。 |
commit and-quit |
[edit] user@host# commit and-quit user@host> |
退出配置模式,无需提交配置。 必须先使用 |
exit |
[edit]
user@host# The configuration has been changed but not committed Exit with uncommitted changes? [yes,no] (yes) |
获取帮助 | ||
显示当前层级的有效选项列表。 |
? |
[edit ]
user@host# Possible completions: <[Enter]> Execute this command > functional-zone Functional zone > security-zone Security zones | Pipe through a command [edit] |
另请参阅
检查瞻博网络设备的状态
在操作模式下,您可以使用 show
命令检查设备状态并监控设备上的活动。
为了帮助您熟悉 show
命令:
键入
show ?
以显示可用于监控路由器的命令列表show
:root@>
show ?
Possible completions: accounting Show accounting profiles and records aps Show Automatic Protection Switching information arp Show system Address Resolution Protocol table entries as-path Show table of known autonomous system paths bfd Show Bidirectional Forwarding Detection information bgp Show Border Gateway Protocol information chassis Show chassis information class-of-service Show class-of-service (CoS) information cli Show command-line interface settings configuration Show current configuration connections Show circuit cross-connect connections dvmrp Show Distance Vector Multicast Routing Protocol info dynamic-tunnels Show dynamic tunnel information information esis Show end system-to-intermediate system information firewall Show firewall information helper Show port-forwarding helper information host Show hostname information from domain name server igmp Show Internet Group Management Protocol information ike Show Internet Key Exchange information ilmi Show interim local management interface information interfaces Show interface information ipsec Show IP Security information ipv6 Show IP version 6 information isis Show Intermediate System-to-Intermediate System info l2circuit Show Layer 2 circuit information l2vpn Show Layer 2 VPN information lacp Show Link Aggregation Control Protocol information ldp Show Label Distribution Protocol information link-management Show link management information llc2 Show LLC2 protocol related information log Show contents of log file mld Show multicast listener discovery information mpls Show Multiprotocol Label Switching information msdp Show Multicast Source Discovery Protocol information multicast Show multicast information ntp Show Network Time Protocol information ospf Show Open Shortest Path First information ospf3 Show Open Shortest Path First version 3 information passive-monitoring Show information about passive monitoring pfe Show Packet Forwarding Engine information pgm Show Pragmatic Generalized Multicast information pim Show Protocol Independent Multicast information policer Show interface policer counters and information policy Show policy information ppp Show PPP process information rip Show Routing Information Protocol information ripng Show Routing Information Protocol for IPv6 info route Show routing table information rsvp Show Resource Reservation Protocol information sap Show Session Announcement Protocol information security Show security information services Show services information snmp Show Simple Network Management Protocol information system Show system information task Show routing protocol per-task information ted Show Traffic Engineering Database information version Show software process revision levels vpls Show VPLS information vrrp Show Virtual Router Redundancy Protocol informationshow chassis routing-engine
使用命令查看路由引擎状态:root@>
show chassis routing-engine
Routing Engine status: Slot 0: Current state Master Election priority Master (default) Temperature 31 degrees C / 87 degrees F CPU temperature 32 degrees C / 89 degrees F DRAM 768 MB Memory utilization 84 percent CPU utilization: User 0 percent Background 0 percent Kernel 1 percent Interrupt 0 percent Idle 99 percent Model RE-2.0 Serial ID b10000078c10d701 Start time 2005-12-28 13:52:00 PST Uptime 12 days, 3 hours, 44 minutes, 19 seconds Load averages: 1 minute 5 minute 15 minute 0.02 0.01 0.00-
show system storage
使用命令查看设备上的可用存储:root@>
show system storage
Filesystem Size Used Avail Capacity Mounted on /dev/ad0s1a 865M 127M 669M 16% / devfs 1.0K 1.0K 0B 100% /dev devfs 1.0K 1.0K 0B 100% /dev/ /dev/md0 30M 30M 0B 100% /packages/mnt/jbase /dev/md1 158M 158M 0B 100% /packages/mnt/jkernel-9.3B1.5 /dev/md2 16M 16M 0B 100% /packages/mnt/jpfe-M7i-9.3B1.5 /dev/md3 3.8M 3.8M 0B 100% /packages/mnt/jdocs-9.3B1.5 /dev/md4 44M 44M 0B 100% /packages/mnt/jroute-9.3B1.5 /dev/md5 12M 12M 0B 100% /packages/mnt/jcrypto-9.3B1.5 /dev/md6 25M 25M 0B 100% /packages/mnt/jpfe-common-9.3B1.5 /dev/md7 1.5G 196K 1.4G 0% /tmp /dev/md8 1.5G 910K 1.4G 0% /mfs /dev/ad0s1e 96M 38K 88M 0% /config procfs 4.0K 4.0K 0B 100% /proc /dev/ad1s1f 17G 2.6G 13G 17% /var
另请参阅
回滚配置更改
本主题说明如何使用 rollback
命令将未提交但已修订的配置返回到最近提交的 Junos OS 配置的状态。进行配置更改后决定不保留更改时,命令 rollback
会很有用。
以下过程说明如何在瞻博网络设备上配置 SNMP 运行状况监视器,然后返回到最近提交的配置(不包括运行状况监视器)。配置 SNMP 运行状况监视器后,即可提供具有设备上文件系统使用情况、CPU 使用情况和内存使用情况预定义监控功能的网络管理系统 (NMS)。
进入配置模式:
user@host>
configure
entering configuration mode [edit] user@host#显示 SNMP 的当前配置(如果有):
[edit] user@host#
show snmp
未出现语句
snmp
,因为设备上尚未配置 SNMP。配置运行状况监视器:
[edit] user@host#
set snmp health-monitor
显示新配置:
[edit] user@host#
show snmp
health-monitor;该
health-monitor
语句表示设备上已配置 SNMP 运行状况监控。输入
rollback
配置模式命令以返回到最近提交的配置:[edit] user@host#
rollback
load complete再次显示配置,确保您的更改不再出现:
[edit] user@host#
show snmp
未
snmp
出现配置语句。运行状况监视器已不再配置。输入
commit
命令以激活已回滚到的配置:[edit] user@host#
commit
退出配置模式:
[edit] user@host#
exit
Exiting configuration mode
您还可以使用 rollback
命令返回到早期配置。
另请参阅
配置路由协议
本主题提供的配置示例介绍如何配置具有两个 SONET 接口的 OSPF 主干区域。
最终配置如下所示:
[edit] protocols { ospf { area 0.0.0.0 { interface so-0/0/0 { hello-interval 5; dead-interval 20; } interface so-0/0/1 { hello-interval 5; dead-interval 20; } } } }
快捷方式
您可以使用以下两个命令为整个配置创建快捷键:
[edit] user@host#set protocols ospf area 0.0.0.0 interface so-0/0/0 hello-interval 5
dead-interval 20
[edit] user@host#set protocols ospf area 0.0.0.0 interface so-0/0/1 hello-interval 5
dead-interval 20
更长的配置
本节提供创建之前的 OSPF 配置的更长的示例。在此过程中,介绍了如何使用 CLI 的不同功能。
更改路由协议配置
假设您决定对接口 so-0/0/1
使用不同的失效间隔和 hello 间隔。您可以对配置进行更改。