
admin@Juniper# rename interfaces ge-0/0/7 to ge-0/0/5
[edit]
admin@Juniper# show |compare
[edit interfaces]
+ ge-0/0/5 {
+ unit 0 {
+ family ethernet-switching {
+ interface-mode access;
+ vlan {
+ members internal;
+ }
+ }
+ }
+ }
- ge-0/0/7 {
- unit 0 {
- family ethernet-switching {
- interface-mode access;
- vlan {
- members internal;
- }
- }
- }
- }
[edit]
admin@Juniper#
工具 7: replace pattern(替换字符串)
相比 rename,replace pattern 的功能更为强大,他可以替换整个 JUNOS 配置里面的参数。假设 ge-0/0/7 被某一个 routing-instance (VRF)调用,在执行 replace pattern ge-0/0/7 with ge-0/0/5 以后,接口配置和 routing-instance 配置都会同时改变。这在大批量修改某一个参数的时候尤其方便。
在此案例中,ge-0/0/7 仅有接口配置,并未被其他协议等调用。所以 show | compare 仅仅替换接口相关参数。
admin@Juniper# replace pattern ge-0/0/7 with ge-0/0/5
替换完成后,使用前面讲到的 show | compare 查看结果,方法如下:
admin@Juniper# show |compare
[edit interfaces]
+ ge-0/0/5 {
+ unit 0 {
+ family ethernet-switching {
+ interface-mode access;
+ vlan {
+ members internal;
+ }
+ }
+ }
+ }
- ge-0/0/7 {
- unit 0 {
- family ethernet-switching {
- interface-mode access;
- vlan {
- members internal;
- }
- }
- }
- }
[edit]
可以看出,运用此工具后,所有的 ge-0/07 都被替换成了 ge-0/0/5。
工具 8: copy (复制某一个变量到其他变量)
如果这个时候,服务器部门又发邮件告知你,索性把ge-0/0/5和ge-0/0/7都配置了吧,很简单,我们把ge-0/0/7的配置复制到ge-0/0/5就行了。
下面我们以ge-0/0/7为模板复制配置到ge-0/0/5。
admin@Juniper# copy interfaces ge-0/0/7 to ge-0/0/5
[edit]
admin@Juniper# show |compare
[edit interfaces]
+ ge-0/0/5 {
+ unit 0 {
+ family ethernet-switching {
+ interface-mode access;
+ vlan {
+ members internal;
+ }
+ }
+ }
+ }
[edit]
admin@Juniper#
完成以上的预配置之后我们需要让其生效。正如我之前提到过,Juniper 的配置是需要 commit 提交以后才能生效的,但是为了避免提交配置以后,出现意外情况导致工程师丢失与路由器的管理连接,JUNOS 引入了自动倒回功能。
工具9: commit confirm xxx comment “xxx” (提交配置,若没有工程师确认,系统会在xx分钟之内倒回,并附上配置备注)
这是 JUNOS 最让人爱不释手的一个功能。先看例子:使用 commit confirm comment 来提交配置
admin@Juniper# commit confirmed 2 comment "add new interfaces as well as vlan configuration"
commit confirmed will be automatically rolled back in 2 minutes unless confirmed
commit complete
# commit confirmed will be rolled back in 2 minutes
[edit]
admin@Juniper#
如上所示,confirm 2 是告知路由器,两分钟之内如果工程师没有确认此配置,那么之前配置的内容将被删除并还原回配置之前的状态。如果在 confirm 之后不加数字,默认是 10 分钟。最低可以设置一分钟。
更贴心的是,你还可以使用 comment 关键字添加备注,这样大大方便了后续核查的时候了解每次操作的大概内容。以上面的配置为例,通过备注可以知道此次配置内容为新增两个接口和一个 vlan。
下面再来演示一下 Juniper 设备在 2 分钟后无人确认配置的情况下,自动倒回的输出:
[edit]
Broadcast Message from root@Juniper
(no tty) at 17:35 NZST...
Commit was not confirmed; automatic rollback complete.
[edit]
admin@Juniper#
那么在 commit 之后,一切工作正常,我如何避免配置被自动倒回呢?
我们只需要在倒回时间超时之前再做一个核查配置的 commit check 就行了。如下所示:
# commit confirmed will be rolled back in 2 minute
[edit]
admin@Juniper# commit check
configuration check succeeds
[edit]
admin@Juniper#
是不是很贴心?
割接中
因为有前期的预配置,割接就显得很轻松了。我们只需要删除 disable 以及 deactivate 的命令行就完成了。这里会用到如下工具:
工具 10: activate(激活忽略的预配置)
通过删除之前的disable 配置,并activate之前的deactivate的配置,就可以激活之前加载的所有预配置。
admin@Juniper# load set terminal
[Type ^D at a new line to end input]
delete interfaces ge-0/0/6 disable
delete interfaces ge-0/0/7 disable
activate interfaces irb unit 5 family inet address192.168.1.1/24
load complete
[edit]
用 show | compare 确认激活行为:
admin@Juniper# show |compare
[edit interfacesge-0/0/6]
- disable;
[edit interfacesge-0/0/7]
- disable;
[edit interfaces irbunit 5 family inet]
! active: address 192.168.1.1/24 { ... }
工具 11: commit at(定点提交配置)
激活配置以后,同样我们也需要向 JUNOS 提交配置,相比之前的 commit confirm,这次我们换一个方法,使用 commitat。如下所示,它会告知路由器,请在晚上 10 点整的时候提交这个配置。(你可以根据自己的时间修改,但是需要比当前时间晚。)
admin@Juniper# commitcomment "cut over the vlan and ge-0/0/5,ge-0/0/6" at 22:00
configuration checksucceeds
commit at will beexecuted at 2017-09-14 22:00:00 NZST
The configuration hasbeen changed but not committed
Exiting configurationmode
如上所示,系统提示配置会在晚上10点被执行。
需要说明的是,为了给大家展现各个工具的使用方法,特地挑选了一个及其简单的案例。但是带来的副作用就是没有完全体现出预先加载割接配置的优势。但是试想一下如果此次割接需要大量的配置,例如大量的 VRF 配置,大量的 BGP 邻居配置以及接口配置等。通过在割接前加载所有配置并 deactivate 掉,割接时只需要少量命令行来 activate 激活预配置,从而大大简化了割接的步骤和复杂度,进而减小了犯错误的可能性。
割接完成
割接完成以后,最重要的就是核查网络运行情况,确认提交的配置是否按照预期运行,并且没有引入任何其他网络故障。为了达到这样的目的,我们可以采用以下介绍的工具:
工具11: monitor interface(设备接口流量监控)
完成接口配置以后,我们需要核查接口是否有流量。如果用传统的 show interface xxx 看到的都是静态数据,那有没有更好的方法?例如动态地观测数据。
借助 monitor interface,我们就可以轻松实现这个功能,如下实例:
admin@Juniper>monitor interface ge-0/0/5
Interface: ge-0/0/5,Enabled, Link is Up
Encapsulation:Ethernet, Speed: 1000mbps
Trafficstatistics: Current delta
<以下为接口实时动态输入输出流量,每秒都在刷新,我只截取了某一秒的输出内容>
Input bytes: 17411220 (200 bps) [52]
Output bytes: 24971481 (947704 bps) [438150]
Input packets: 324059 (0 pps) [1]
Output packets: 319355 (789 pps) [2921]
Errorstatistics:
Input errors: 0 [0]
Input drops: 0 [0]
Input framing errors: 0 [0]
Policed discards: 0 [0]
L3 incompletes: 0 [0]
L2 channel errors: 232 [0]
L2 mismatch timeouts: 0 [0]
Carrier transitions: 1 [0]
Output errors: 0 [0]
Output drops: 0 [0]
Aged packets: 0 [0]
<为了便于阅读,此处省略了其他无关的输出内容>
此命令是每秒钟都在刷新,如果大家有条件可以在设备上尝试一下,博客上无法动态展现给大家。
工具 12: monitor traffic interface (cli 层面的tcpdump 数据抓包)
有些时候配置了路由协议,但是发现其没有正常工作,在开启 debug 模式之前,我们还有一个最简单的办法来排错,那就是抓包。
想到抓包,大家是不是第一印象就是做镜像端口,然后把 PC 接入设备用 Wireshark 抓取。
在 Juniper 设备上,如果你只是想抓取到达路由器本身的流量,例如像上面所述的路由协议排查,我们可以很简单地在命令行模式下抓取到达路由器的数据包。
下面演示一个命令行模式下用 monitor trafficinterface 的抓包:
admin@Juniper>monitor traffic interface ge-1/1/4.100 no-resolve
verbose outputsuppressed, use <detail> or <extensive> for full protocol decode
Address resolution isOFF.
Listening onge-1/1/4.100, capture size 96 bytes
s00:46:38.271636 In IP 1.2.3.4.179 > 1.2.3.5.61855: P662902184:662902203(19) ack 2900796289 win 16384 <nop,nop,timestamp3271803181 643396392>: BGP, length: 19
00:46:38.371433 Out IPtruncated-ip - 2 bytes missing! 1.2.3.5.61855 > 1.2.3.4.179: . ack 19 win16384 <nop,nop,timestamp 643418995[|tcp]>
00:46:38.724938 OutIS-IS, L2 Lan IIH, src-id 0011.0000.0001, lan-id 0011.0000.0001.03, prio 64,length 47
00:46:39.174455 OutES-IS, ISH, length 26
00:46:41.199436 OutIS-IS, L2 Lan IIH, src-id 0011.0000.0001, lan-id 0011.0000.0001.03, prio 64,length 47
00:46:42.161045 In IS-IS, L2 Lan IIH, src-id 0011.0000.0254,lan-id 0011.0000.0001.03, prio 64, length 47
00:46:42.481016 OutIS-IS, L2 CSNP, src-id 0011.0000.0001.00, length 47
00:46:43.797914 OutIS-IS, L2 Lan IIH, src-id 0011.0000.0001, lan-id 0011.0000.0001.03, prio 64,length 47
00:46:43.864907 Out IPtruncated-ip - 21 bytes missing! 1.2.3.5.61855 > 1.2.3.4.179: P 1:20(19) ack19 win 16384 <nop,nop,timestamp 643424488[|tcp]>
00:46:43.964852 In IP 1.2.3.4.179 > 1.2.3.5.61855: . ack20 win 16384 <nop,nop,timestamp 3271808875 643424488>
00:46:46.147386 OutIS-IS, L2 Lan IIH, src-id 0011.0000.0001, lan-id 0011.0000.0001.03, prio 64,length 47
00:46:48.400363 OutIS-IS, L2 Lan IIH, src-id 0011.0000.0001, lan-id 0011.0000.0001.03, prio 64,length 47
00:46:49.340934 In IS-IS, L2 Lan IIH, src-id 0011.0000.0254,lan-id 0011.0000.0001.03, prio 64, length 47
^C
15 packets received byfilter
0 packets dropped bykernel
从上面输出可以看出,两台路由器之间有 BGP 通信流量,同时还有 IS-IS IGP 路由协议流量。
当然,monitor traffic interface 还有更多选项。例如 extensive 可以看到更多的数据包内容,通过 match 可以像 tcpdump 一样,设定源、目标地址,端口等信息来过滤数据包。
工具 13: show interface terse | refresh xxx (定期自动刷新)
此工具是用于定时自动刷新某些显示的命令行内容。打个比方,有时候我们难免遇到需要同远端联调设备端口。在完成相应配置后,双方需要确认接口是否 up。一般方法是按向上的方向键调出命令不断手工刷新状态,其实更简单的办法就是使用 refresh。
Refresh 可以用于任何状态显示的自动定期刷新,例如定期接口状态,定期刷新 OSPF,ISIS,BGP 邻居状态等。
如下案例,设定路由器每 1 秒钟自动刷新一次接口状态。
admin@Juniper> showinterfaces terse ge-0/0/2 | refresh 1 | no-more
---(refreshed at2017-09-14 22:00:55 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
---(refreshed at2017-09-14 22:00:56 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
---(refreshed at2017-09-14 22:00:58 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
---(refreshed at2017-09-14 22:00:59 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
---(refreshed at2017-09-14 22:01:00 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
---(refreshed at2017-09-14 22:01:01 NZST)---
Interface Admin Link Proto Local Remote
ge-0/0/2 up up
ge-0/0/2.10 up up
ge-0/0/2.32767 up up
### 割接结束 ####
以上就是在使用 Juniper 设备过程中常用的运维技巧和方法,相信有了这么多工具和思路的帮助下,对于大家的日常工作相比原来是否就不那么恐慌了。至少可以对自己的配置胸有成竹,自信的敲下 commit 的回车键了!
疫情期间不能出门,你做了哪些秘密训练?如何短时间成为同学口中的神秘网工大神?方案在这里!拥有多年网络项目经验,精通思科、华为、H3C、Juniper等主流厂商配置专业讲师倾情教授,本课程含概了网络基础入门课:CCNA+HCIA所有知识点,内容丰富全面,价格低!包含网工职业发展介绍、网络基础原理、路由交换基础知识以及广域网模块等必备技术,每天2小时,一周学会搭建小型局域网,适合0基础在校小白快速入行!更多详情可联系QQ:839898248,微信:Ciscolnfinity,名额有限,点击下方链接快来报名吧
↓↓↓↓↓↓
https://ke.qq.com/course/1406048tuin=50ba6ed6



本文地址:http://www.023wg.com/867.html
版权声明:若无注明,本文皆为“Swiers思唯网络博客”原创,转载请保留文章出处。

