回車恐懼症?13個技巧助你輕鬆無憂配置網絡

回車恐懼症?13個技巧助你輕鬆無憂配置網絡

回車恐懼症?13個技巧助你輕鬆無憂配置網絡

<code>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#/<code>


工具 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 僅僅替換接口相關參數。

<code>admin@Juniper# replace pattern ge-0/0/7 with ge-0/0/5/<code>


替換完成後,使用前面講到的 show | compare 查看結果,方法如下:

<code>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]/<code>


可以看出,運用此工具後,所有的 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。

<code>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#/<code>

完成以上的預配置之後我們需要讓其生效。正如我之前提到過,Juniper 的配置是需要 commit 提交以後才能生效的,但是為了避免提交配置以後,出現意外情況導致工程師丟失與路由器的管理連接,JUNOS 引入了自動倒回功能。


工具9: commit confirm xxx comment “xxx” (提交配置,若沒有工程師確認,系統會在xx分鐘之內倒回,並附上配置備註)


這是 JUNOS 最讓人愛不釋手的一個功能。先看例子:使用 commit confirm comment 來提交配置

<code>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#/<code>


如上所示,confirm 2 是告知路由器,兩分鐘之內如果工程師沒有確認此配置,那麼之前配置的內容將被刪除並還原回配置之前的狀態。如果在 confirm 之後不加數字,默認是 10 分鐘。最低可以設置一分鐘。


更貼心的是,你還可以使用 comment 關鍵字添加備註,這樣大大方便了後續核查的時候瞭解每次操作的大概內容。以上面的配置為例,通過備註可以知道此次配置內容為新增兩個接口和一個 vlan。


下面再來演示一下 Juniper 設備在 2 分鐘後無人確認配置的情況下,自動倒回的輸出:

<code>[edit]
                                                                              
Broadcast Message from root@Juniper                                            
        (no tty) at 17:35 NZST...                                              
                                                                              
Commit was not confirmed; automatic rollback complete.                                                                              

 
[edit]
admin@Juniper#/<code>


那麼在 commit 之後,一切工作正常,我如何避免配置被自動倒回呢?


我們只需要在倒回時間超時之前再做一個核查配置的 commit check 就行了。如下所示:

<code># commit confirmed will be rolled back in 2 minute
[edit]

admin@Juniper# commit check

configuration check succeeds
 
[edit]
admin@Juniper#/<code>


是不是很貼心?



割接中


因為有前期的預配置,割接就顯得很輕鬆了。我們只需要刪除 disable 以及 deactivate 的命令行就完成了。這裡會用到如下工具:


工具 10: activate(激活忽略的預配置)

通過刪除之前的disable 配置,並activate之前的deactivate的配置,就可以激活之前加載的所有預配置。

<code>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]/<code>


用 show | compare 確認激活行為:

<code>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 { ... }/<code>


工具 11: commit at(定點提交配置)

激活配置以後,同樣我們也需要向 JUNOS 提交配置,相比之前的 commit confirm,這次我們換一個方法,使用 commitat。如下所示,它會告知路由器,請在晚上 10 點整的時候提交這個配置。(你可以根據自己的時間修改,但是需要比當前時間晚。)

<code>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/<code>

如上所示,系統提示配置會在晚上10點被執行。


需要說明的是,為了給大家展現各個工具的使用方法,特地挑選了一個及其簡單的案例。但是帶來的副作用就是沒有完全體現出預先加載割接配置的優勢。但是試想一下如果此次割接需要大量的配置,例如大量的 VRF 配置,大量的 BGP 鄰居配置以及接口配置等。通過在割接前加載所有配置並 deactivate 掉,割接時只需要少量命令行來 activate 激活預配置,從而大大簡化了割接的步驟和複雜度,進而減小了犯錯誤的可能性。



割接完成


割接完成以後,最重要的就是核查網絡運行情況,確認提交的配置是否按照預期運行,並且沒有引入任何其他網絡故障。為了達到這樣的目的,我們可以採用以下介紹的工具:


工具11: monitor interface(設備接口流量監控)

完成接口配置以後,我們需要核查接口是否有流量。如果用傳統的 show interface xxx 看到的都是靜態數據,那有沒有更好的方法?例如動態地觀測數據。


藉助 monitor interface,我們就可以輕鬆實現這個功能,如下實例:

<code>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]
 
/<code>

此命令是每秒鐘都在刷新,如果大家有條件可以在設備上嘗試一下,博客上無法動態展現給大家。


工具 12: monitor traffic interface (cli 層面的tcpdump 數據抓包)

有些時候配置了路由協議,但是發現其沒有正常工作,在開啟 debug 模式之前,我們還有一個最簡單的辦法來排錯,那就是抓包。


想到抓包,大家是不是第一印象就是做鏡像端口,然後把 PC 接入設備用 Wireshark 抓取。


在 Juniper 設備上,如果你只是想抓取到達路由器本身的流量,例如像上面所述的路由協議排查,我們可以很簡單地在命令行模式下抓取到達路由器的數據包。


下面演示一個命令行模式下用 monitor trafficinterface 的抓包:

<code>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 : 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 

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 
00:46:43.964852  In IP 1.2.3.4.179 > 1.2.3.5.61855: . ack20 win 16384 
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
/<extensive>/<detail>/<code>


從上面輸出可以看出,兩臺路由器之間有 BGP 通信流量,同時還有 IS-IS IGP 路由協議流量。


當然,monitor traffic interface 還有更多選項。例如 extensive 可以看到更多的數據包內容,通過 match 可以像 tcpdump 一樣,設定源、目標地址,端口等信息來過濾數據包。


工具 13: show interface terse | refresh xxx (定期自動刷新)

此工具是用於定時自動刷新某些顯示的命令行內容。打個比方,有時候我們難免遇到需要同遠端聯調設備端口。在完成相應配置後,雙方需要確認接口是否 up。一般方法是按向上的方向鍵調出命令不斷手工刷新狀態,其實更簡單的辦法就是使用 refresh。


Refresh 可以用於任何狀態顯示的自動定期刷新,例如定期接口狀態,定期刷新 OSPF,ISIS,BGP 鄰居狀態等。


如下案例,設定路由器每 1 秒鐘自動刷新一次接口狀態。

<code>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/<code>

### 割接結束 ####


以上就是在使用 Juniper 設備過程中常用的運維技巧和方法,相信有了這麼多工具和思路的幫助下,對於大家的日常工作相比原來是否就不那麼恐慌了。至少可以對自己的配置胸有成竹,自信的敲下 commit 的回車鍵了!


分享到:


相關文章: