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

回車鍵,平常電腦使用中,扮演「確認」或「執行」事件的功效。服務器


在網絡工程師的平日運維工做中,不管是計劃性的網絡配置修改,仍是臨時性的故障處理,你們是否都存在一樣的感覺:特別當心敲擊回車鍵,再三確認之後才執行網絡


相信如下場景是不少作網絡的朋友曾經都遇到過的,在遠程配置 Cisco 或者其餘廠商路由器或交換機時,一頓複製粘貼而後敲下回車結果就是這樣:app

1. 配錯接口 IP 地址——Game Over!less

2. 修改靜態路由條目或者動態路由協議,致使路由丟失----Game Over!運維

3. 配置錯 VLAN ID 或者二層接口 ACCESS/TRUNK 配置錯誤----Game Over!tcp


這個時候大部分人都是一臉驚慌,腦子琢磨怎麼解決:給遠端人員打電話把路由器交換機重啓。反正配置沒保存呢,重啓就回來了。ide


可是若是遠端就是客戶的話,後面幾天日子恐怕就不太好過了。要是這是公司另一個廠房的核心交換,這事兒就大了。重啓是不可能了,再去現場花費的時間成本無可估量。工具


總的來講,在作平常網絡配置中,回車恐懼症來源於以下幾個方面:測試

● 對本身準備的配置沒信心,擔憂配置中有低級錯誤spa

● 懼怕配置設備過程當中遇到意料以外的問題

● 和對端聯調的時候,不信任對端,懼怕遠端工程師犯錯致使聯調不成功


以上的問題也曾讓我在平常運維中頭疼不已。直到後來我入職某運營商後,不管從客戶的 CPE,到核心 PE,BNG 或者 P 路由器,絕大部分設備都是 Juniper。在慢慢從 Cisco 習慣過渡到 Juniper 的過程當中,我發現這些擔心和問題極大地減小了。並且準確來講你有很大的機會在敲回車執行之間,就已經發現錯誤並予以糾正。


那到底在 Juniper 環境下,有什麼行之有效並且簡單易用的工具可以解決工程師的煩惱呢?


爲了回答上面的問題,我將用一個平常割接流程來給你們揭曉答案。


說到割接流程,無非就三點: 

● 割接前期配置準備

● 進行割接

● 割接後複查


在介紹這些技巧以前,先給較少接觸過 Juniper 設備的朋友們作個知識鋪墊:和 Cisco 的 IOS 系統配置模式不一樣,JUNOS 系統配置模式裏面,配置修改並非當即生效。你能夠隨意增添甚至刪除整個設備配置,只有你在經過 commit 提交配置後,纔會生效。


(PS:請勿在現網設備隨意模仿,能夠在Juniper實驗室或者模擬器上測試。)



割接前期配置準備


在前期配置準備過程當中,咱們怎麼保證預配置沒有低級錯誤,如打錯字符,寫錯 IP 等?難道要每次都把預配置加載到實驗室設備或者模擬器上跑一遍看看?


另外,因爲配置腳本行數多,配置量大。在割接期間逐個複製粘貼很耗費時間;同時,在複製粘貼過程當中,若是人眼跟蹤不及時,容易忽略設備提示的錯誤。


那麼,下面讓咱們用一個簡單的例子來講明 JUNOS 都有哪些工具可以解決以上問題。

 

案例:

某部門計劃隔天割接幾臺關鍵服務器到另一臺 Juniper 設備上,工程師計劃配置一個新的 vlan 及 vlan interface。並劃分兩個物理接口到這個新 vlan 內。如下爲該工程師作的預配置: 

set interfaces ge-0/0/6 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/6 unit 0 family ethernet-switching vlan members internal
set interfaces ge-0/0/7 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/7 unit 0 family ethernet-switching vlan members internal
 
set interfaces irb unit 5 family inet address 192.168.1.1/24
 
set vlans internal vlan-id 5
set vlans internal l3-interface irb.5


問題 1:通常狀況,工程師會等到割接時才把全部準備的配置加載到設備上,那咱們能否在準備配置前期提早加載到設備上?等到割接的時候,只須要執行幾條關鍵的命令,就完成整個割接?這樣既節省時間,也減小了出錯率。

 

答案是能夠的,上工具!


工具 1: load set terminal (加載set命令的配置,若是有語法錯誤會當即提醒)

load set terminal 是一個批量添加配置的工具,相比逐個命令複製粘貼,批量添加的好處是配置清晰明瞭。能夠一目瞭然地發現錯誤的參數,尤爲是在配置行數特別多的狀況下,很是方便工程師查錯。


它還有其餘孿生兄弟,例如:load merge terminal,load patch terminal等。具體你們能夠查閱Juniper文檔。


讓咱們使用 load set terminal 把工程師準備的割接配置加載到設備上,方法以下: 

admin@Juniper>configure 
Entering configuration mode
 
admin@Juniper# load set terminal 
[Type ^D at a new line to end input]
set interfaces ge-0/0/6 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/6 unit 0 family ethernet-switching vlan members internal
set interfaces ge-0/0/7 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/7 unit 0 family ethernet-switching vlan members internal
 
set interfaces irbunit 5 family inet address 192.168.1.1/24
 
set vlans internal vlan-id 5
set vlans internal l3-interface irb.5
load complete
 
[edit]
admin@Juniper#

當全部命令加載完畢之後,鍵入 Ctrl+D 後就能夠結束 load setterminal 的界面並回到了配置模式下。


工具 2: deactivate(告知 JUNOS 忽略某配置)

經過 deactivate 這一配置技巧,咱們能夠人爲地忽略某配置。從而讓 JUNOS 在讀取配置的時候,不讀取對應的配置參數。可是在經過 show configuration 的時候,仍然可見。


回到案例中,爲了不割接前配置的 vlan 接口 irb.5 的 IP 地址被其餘路由協議發佈到網絡中,咱們先把它 deactivate 掉。方法以下: 

[edit]
admin@Juniper# deactivate interfaces irb unit 5 family inet address 192.168.1.1/24


工具 3: disable (admin shut down某接口)

disable 就等同於 Cisco 的接口 shutdown。與 Cisco 類似,它也只能應用於接口級別。


爲了讓接口在割接前不開啓,咱們能夠 shutdown ge-0/0/6 以及 ge-0/0/7 接口。方法以下:

admin@Juniper# set interfacesge-0/0/6 disable 
 
[edit]
admin@Juniper# setinterfaces ge-0/0/7 disable


最後,讓咱們來看看經過以上工具配置後的最終結果:

admin@Juniper# show interfaces | display set 
setinterfaces ge-0/0/6 disable
set interfacesge-0/0/6 unit 0 family ethernet-switching interface-mode access
set interfacesge-0/0/6 unit 0 family ethernet-switching vlan members internal
setinterfaces ge-0/0/7 disable
set interfacesge-0/0/7 unit 0 family ethernet-switching interface-mode access
set interfacesge-0/0/7 unit 0 family ethernet-switching vlan members internal
set interfaces irb unit 5 family inet address 192.168.1.1/24
deactivate interfaces irb unit 5 family inet address 192.168.1.1/24
 
admin@Juniper# show vlans | display set 
set vlans internal vlan-id 5
set vlans internal l3-interface irb.5

這裏你可能會注意到在每一個配置裏面,都有一個對應的 deactivate 或者 disable 配置。


Tips:deactivate 和 disable 有什麼區別?

disable 等同於 Cisco 的 shutdown,可是 JUNOS 系統會繼續讀取 ge-0/0/6 或者 ge-0/0/7 的接口配置,只是把它admin down了而已。

而 deactivate 直接讓 JUNOS 忽略此配置,雖然你經過 show config 仍然能看見 irb unit 5 的 IP 地址,可是對於設備自己來講,它會徹底忽略此IP。


問題 2:預配置完成之後,如何經過JUNOS覈查配置錯誤,如何知道當前的配置與現有配置是否衝突呢?


工具 4: show | compare (對比原配置和加載的新配置之間的區別)

show | compare可以對比配置先後的差異,從而看出配置是否有誤。


在本案例中,使用 show | compare 能夠對比配置加載先後的區別,方法以下:

admin@Juniper# show |compare 
[edit interfaces]
+   ge-0/0/6 {
+       disable;
+       unit 0 {
+           family ethernet-switching {
+               interface-mode access;
+               vlan {
+                   members internal;
+               }
+           }
+       }
+   }
+   ge-0/0/7 {
+       disable;
+       unit 0 {
+           family ethernet-switching {
+               interface-mode access;
+               vlan {
+                   members internal;
+               }
+           }
+       }
+   }
[edit interfaces irb]
+    unit 5 {
+        family inet {
+            inactive: address 192.168.1.1/24;
+        }
+    }
[edit vlans]
+   internal {
+       vlan-id 5;
+       l3-interface irb.5;
+   }
 
[edit]
admin@Juniper#

你能夠看到,左邊爲加號(+),證實此配置是新增配置。若是是減號(-),那麼表明刪除配置。


爲了增強對這個工具的理解,下面再加一個示例:


### 額外示例 ###

某個工程師準備把接口 ge-0/0/5 從 access 模式變爲 trunk 模式,並新增一個 Internet 的 vlan 在此接口下。完成配置並 show | compare 後,經過加減號就能夠知道哪一個配置刪除了,哪一個配置是新增的。示例以下:

admin@Juniper# show |compare 
[edit interfaces ge-0/0/5 unit 0 family ethernet-switching]
-      interface-mode access;
+      interface-mode trunk;
[edit interfaces ge-0/0/5 unit 0 family ethernet-switching vlan]
-       members MGMT;
+       members [ MGMT Internet ];

注意,show | compare 在平常 Juniper 運維中,佔據了很是重要的角色,經過 show| compare 你能夠清楚知道本身的配置是否符合預期。


工具5: commit check (設備配置自動覈查)

經過 commit check,可以在提交配置以前,作最後一步的系統配置自檢。


回到咱們開頭的案例。完成 show | compare 的檢查之後,咱們繼續讓 JUNOS 自行檢查配置: 

[edit]
admin@Juniper# commit check 

configuration check succeeds
 
[edit]
admin@Juniper#

commit check 會告知你配置是否有誤,是否與其餘配置有衝突等。上面輸出能夠看出咱們的配置沒有問題。接下來就能夠放心去提交配置了。

 

問題 3:在配置中若是須要修正錯誤配置或須要新增其餘配置時,如何簡潔高效地完成任務?


有些時候,你們載入配置過程當中,發現腳本里面接口配置錯誤,或者IP地址配置錯誤。按照通常思路來的話,確定是刪除掉此命令,而後再重配置一遍。其實還有比這個更簡單的方法,咱們來看看對比:


上面的案例裏,咱們配置了 ge-0/0/6 和 ge-0/0/7 兩個接口。假設服務器部門告訴你,正確接口應該是 ge-0/0/5,你須要把 ge-0/0/7 的配置挪到 ge-0/0/5 上。


傳統方法:

delete interfaces ge-0/0/7 
 
set interfaces ge-0/0/5 disable
set interfaces ge-0/0/5 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/5 unit 0 family ethernet-switching vlan members internal


而更簡單的方法能夠用到如下工具:

 

工具 6: rename (重命名某一個變量)

顧名思義,rename 能夠把你在 JUNOS 內配置的任何參數變量重命名。在這裏咱們把接口 ge-0/0/7 重命名爲 ge-0/0/5,全部 ge-0/0/7 相關的配置被挪到 ge-0/0/5 層級之下。

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(替換字符串)

相比 renamereplace 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 鄰居狀態等。


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

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 的回車鍵了!




附錄:如下爲額外贈送的福利,拿走不謝。


福利一:apply-group

你是否是在配置 Juniper SRX 的時候但願在每個 zone 層級下配置 host-inbound-traffic 容許基本的 ping 和 traceroute。


例若有三個 zone:internal,external,dmz。普通的方法就是針對每個 zone,配置對應的 host-inbound-policy,其實還有更簡單的方法,那就是利用 apply-group。


示例:

set groups ALLOW_PING_TRACEsecurity zones security-zone <*> interfaces <*>host-inbound-traffic system-services ping
set groupsALLOW_PING_TRACE security zones security-zone <*> interfaces <*>host-inbound-traffic system-services traceroute


你會發現這裏使用了通配符。這就是祕訣所在,經過通配符的方式,你能夠匹配任意的 security zone 的任意接口。並在其底下容許 ping 和 traceroute


應用 groups:

set security zonesapply-groups ALLOW_PING_TRACE


查看配置,以 internal zone 爲例:

admin@JuniperSRX>show configuration security zones security-zone internal |display set            
set security zones security-zoneinternal interfaces irb.5


貌似沒看見配置?別急,讓咱們使用 inheritance 的查看方式,此命令用於查看從其餘地方繼承下來的配置,例如上文的 groups 配置。 

lg@JuniperSRX>show configuration security zones security-zone internal |display inheritance 
interfaces {
    irb.5 {
        ##
        ## 'host-inbound-traffic' was inheritedfrom group ALLOW_PING_TRACE
        ##
        host-inbound-traffic {
            system-services {
                ##
                ## 'ping' was inherited fromgroup ALLOW_PING_TRACE
                ##
                ping;
                ##
                ## 'traceroute' was inheritedfrom group ALLOW_PING_TRACE
                ##
                traceroute;
            }
        }
    }
}


福利二:apply-path

你們在配置 Juniper 路由器自身防禦的時候,但願只容許設備配置的 BGP 鄰居與設備經過 TCP 端口 179 通信,對於其餘未配置的 BGP 鄰居丟棄目標爲 TCP 端口 179 的數據。


一般方法爲,先蒐集設備配置的全部 BGP 鄰居 IP 地址,在 firewall filter 裏面逐個添加。


費時費力不說,最不方便的是它是靜態配置,若是後續有新的 BGP 鄰居添加的時候,還得同步更新此 firewall filter。


那有什麼既省時,又省力的方法呢?讓咱們來看看神奇的 apply-path


示例:

在這一臺 MX 路由器上,有以下的 BGP 鄰居配置:

admin@MX480> show configuration | grep bgp | display set | except "firewall|policy" |grep local-add 

set protocols bgp group TO_RR local-address 1.1.0.1

set routing-instances Internet protocols bgp group UpStream_Peering neighbor 2.2.2.1 local-address2.2.2.2

set routing-instances Internet protocols bgp group UpStream_Peering-IPv6 neighbor 2:2:37::2local-address 2:2:37::1

set routing-instances Internet protocols bgp group CUSTOMER_InternetA neighbor 1.1.4.4 local-address1.1.4.5

set routing-instances Internet protocols bgp group CUSTOMER_InternetA-IPv6 neighbor 1:1:4::4local-address 1:1:4::5

set routing-instances VRF_A protocols bgp group customer_A neighbor 10.10.2.100 local-address10.10.2.1

set routing-instances VRF_A protocols bgp group customer_A_v6 neighbor 10:10:2::100 local-address10:10:2::1

set routing-instances VRF_A protocols bgp group customer_B_v6 neighbor 10:10:20::100 local-address10:10:20::1


經過 apply-path 自動挑出鄰居 IP


先在 prefix-list 裏面定義 apply-path:

set policy-optionsprefix-list bgp-neighbors apply-path "protocols bgp group <*>neighbor <*>"

set policy-optionsprefix-list bgp-neighbors-logical-systems apply-path "logical-systems<*> protocols bgp group <*> neighbor <*>"

set policy-optionsprefix-list bgp-neighbors-routing-instance apply-path "routing-instances<*> protocols bgp group <*> neighbor <*>"

set policy-optionsprefix-list bgp-neighbors-routing-instance-logical-systems apply-path"logical-systems <*> routing-instances <*> protocols bgp group<*> neighbor <*>"


這個命令會挑出符合以上路徑的最後一個通配符的數值,在這裏就是 neighbor 後面的 IP 地址。通常狀況在 Juniper 裏面 bgp 會存在於三個地方,全局路由表下,VRF 下,以及邏輯路由器下。因此上面就定義了三個 apply-path,並分別放置在不一樣的 prefix-list 內部。


讓咱們來查看一下匹配是否成功,仍是經過 inheritance 查看全局路由表的 BGP 鄰居匹配狀況:

admin@MX480# showpolicy-options prefix-list bgp-neighbors | display inheritance 
##
## apply-path wasexpanded to:
##     1.1.0.1/32; 
##
apply-path"protocols bgp group <*> neighbor <*>";


最後就是引用prefix-list :

set firewall family inet filter router-protect term 1-accept-bgp from source-prefix-list bgp-neighbors

set firewall family inet filter router-protect term 1-accept-bgp from source-prefix-list bgp-neighbors-routing-instance

set firewall family inet filter router-protect term 1-accept-bgp from source-prefix-list bgp-neighbors-logical-systems

set firewall family inet filter router-protect term 1-accept-bgp from source-prefix-list bgp-neighbors-routing-instance-logical-systems

set firewall family inet6 filter router-protect6 term 1-accept-bgp from source-prefix-list bgp-neighbors

set firewall family inet6 filter router-protect6 term 1-accept-bgp from source-prefix-list bgp-neighbors-routing-instance

set firewall family inet6 filter router-protect6 term 1-accept-bgp from source-prefix-list bgp-neighbors-logical-systems

set firewall family inet6 filter router-protect6 term 1-accept-bgp from source-prefix-list bgp-neighbors-routing-instance-logical-systems


並把 firewall filter 應用到 lo0 接口上。(注:在 Juniper 的 JUNOS 內,路由器防禦通常方法就是添加 ACL 並綁定在 lo0 接口上)

set interfaces lo0 unit 0 family inet filter input router-protect
set interfaces lo0 unit 0 family inet6 filter input router-protect6


大功告成!碼字很辛苦,贊一個吧?

相關文章
相關標籤/搜索