Site icon KerKer 的模組世界

[Juniper] Junos動態路由OSPF路由重分發(redistribute route)

&NewLine;<p class&equals;"wp-block-paragraph">邊做邊學,順便留個筆記,若有錯誤請不吝指教。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">Junos基本操作及root密碼設定可參考我之前的文章:<a href&equals;"https&colon;&sol;&sol;kerker&period;website&sol;juniper-junos&percnt;E5&percnt;9F&percnt;BA&percnt;E6&percnt;9C&percnt;AC&percnt;E6&percnt;93&percnt;8D&percnt;E4&percnt;BD&percnt;9C&percnt;E3&percnt;80&percnt;81root&percnt;E5&percnt;AF&percnt;86&percnt;E7&percnt;A2&percnt;BC&percnt;E8&percnt;A8&percnt;AD&percnt;E5&percnt;AE&percnt;9A&sol;">Juniper Junos基本操作、root密碼設定<&sol;a><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">所有Juniper相關文章列表:<a href&equals;"https&colon;&sol;&sol;kerker&period;website&sol;juniper-junos-&percnt;E7&percnt;B3&percnt;BB&percnt;E5&percnt;88&percnt;97-&percnt;E6&percnt;96&percnt;87&percnt;E7&percnt;AB&percnt;A0&percnt;E5&percnt;88&percnt;97&percnt;E8&percnt;A1&percnt;A8&sol;">Juniper JunOS 系列文章列表<&sol;a><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<&excl;--more-->&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">關於OSPF的基本設定可以參考:<a href&equals;"https&colon;&sol;&sol;kerker&period;website&sol;juniper-junos&percnt;e5&percnt;8b&percnt;95&percnt;e6&percnt;85&percnt;8b&percnt;e8&percnt;b7&percnt;af&percnt;e7&percnt;94&percnt;b1ospf&percnt;e5&percnt;9f&percnt;ba&percnt;e6&percnt;9c&percnt;ac&percnt;e8&percnt;a8&percnt;ad&percnt;e5&percnt;ae&percnt;9a&sol;" class&equals;"aioseop-link">Junos動態路由OSPF基本設定<&sol;a><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">OSPF提供了將外部路由加入OSPF網路作路由交換的功能,這裡以將Direct link的路由轉送到OSPF網路為例。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">架構圖與基本設定時使用的架構相同,且已經先將所有介面&lpar;除irb&period;100、irb&period;200外&rpar;加入OSPF area 0&period;0&period;0&period;0 中了。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image size-large"><img src&equals;"https&colon;&sol;&sol;lh3&period;googleusercontent&period;com&sol;pw&sol;AP1GczPxMkb7af5Y4Afaqmg8E5nvH9KD9ypYsG8nxYNax46IbaWp1jXvsPMHGN2TreOVVPasTnTMElCNLeyePviPkdUYr1f5iB1ccj8dI0fHaeAidIbJQy&fjlig;cjtkuMJTzRXHA76qsqKi-BSFnPfXBgWphwb&lowbar;&equals;w439-h471-s-no-gm&quest;authuser&equals;0" alt&equals;""&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">首先要建立一個policy-statement作為路由會匯入的規則,只要是來自protocol direct的路由就都轉送到OSPF。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 1 from protocol direct&NewLine; KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 1 then accept&NewLine; KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 2 then reject<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">policy-statement設定檔完成後大概會長這樣:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show configuration policy-options policy-statement direct&lowbar;to&lowbar;ospf &NewLine; term 1 &lbrace;&NewLine; from protocol direct&semi;&NewLine; then accept&semi;&NewLine; &rcub;&NewLine; term 2 &lbrace;&NewLine; then reject&semi;&NewLine; &rcub;<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">將剛剛設定好的policy-statement套用到OSPF的export上:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set protocols ospf export direct&lowbar;to&lowbar;ospf<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">可以透過在命令模式下show ospf database來確認是否有成功匯入外部路由:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show ospf database &NewLine; &period;&period;&period;&NewLine; OSPF AS SCOPE link state database&NewLine; Type ID Adv Rtr Seq Age Opt Cksum Len &NewLine; Extern 192&period;168&period;100&period;0 10&period;0&period;0&period;3 0x80000001 474 0x22 0x9245 36&NewLine; Extern 192&period;168&period;200&period;0 10&period;0&period;0&period;3 0x80000001 474 0x22 0x4231 36<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">如果不想匯入某些路由,可以在policy-statement作過濾,這裡以過濾掉192&period;168&period;100&period;0&sol;24為例,在原本的policy-statement中加入一個新的term作過濾:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 from route-filter 192&period;168&period;100&period;0&sol;24 exact&NewLine; KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 then reject&NewLine; KerKer&commat;sw3&num;insert policy-statement direct&lowbar;to&lowbar;ospf term 0 before term 1 <&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">policy-statement設定檔完成後大概會長這樣:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show configuration policy-options policy-statement direct&lowbar;to&lowbar;ospf&NewLine; term 0 &lbrace;&NewLine; from &lbrace;&NewLine; route-filter 192&period;168&period;100&period;0&sol;24 exact&semi;&NewLine; &rcub;&NewLine; then reject&semi;&NewLine; &rcub;&NewLine; term 1 &lbrace;&NewLine; from protocol direct&semi;&NewLine; then accept&semi;&NewLine; &rcub;&NewLine; term 2 &lbrace;&NewLine; then reject&semi;&NewLine; &rcub;<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">這裡提一下route-filter後接的exact代表遮罩長度要與設定的prefix相同,在我們的例子中就是24,其他還有longer、orlonger、prefix-length-range等用來判斷prefix遮罩長度的作法。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">查看ospf database確認是否成功過濾:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show ospf database &NewLine; &period;&period;&period;&NewLine; OSPF AS SCOPE link state database&NewLine; Type ID Adv Rtr Seq Age Opt Cksum Len &NewLine; Extern 192&period;168&period;200&period;0 10&period;0&period;0&period;3 0x80000001 474 0x22 0x4231 36<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">除了使用route-filter作過濾外,也可以引入prefix-list作過濾,這裡先將剛剛作的route-filter刪除。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;delete policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 from route-filter 192&period;168&period;100&period;0&sol;24 exact<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">新增一個prefix-list包含不匯入的路由,並在policy-statement中設定prefix-list-filter:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set policy-options prefix-list no&lowbar;redistribute 192&period;168&period;100&period;0&sol;24&NewLine; KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 from prefix-list-filter no&lowbar;redistribute exact<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">policy-statement設定檔完成後大概會長這樣,這樣作的效果與剛剛使用route-filter的效果是一致的:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show configuration policy-options policy-statement direct&lowbar;to&lowbar;ospf&NewLine; term 0 &lbrace;&NewLine; from &lbrace;&NewLine; prefix-list-filter no&lowbar;redistribute exact&semi;&NewLine; &rcub;&NewLine; then reject&semi;&NewLine; &rcub;&NewLine; term 1 &lbrace;&NewLine; from protocol direct&semi;&NewLine; then accept&semi;&NewLine; &rcub;&NewLine; term 2 &lbrace;&NewLine; then reject&semi;&NewLine; &rcub;<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">最後分享一下實務上常用到的,將Private IP的路由過濾掉不匯入OSPF的做法。<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">一樣先將剛剛作的設定刪除:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;delete policy-options prefix-list no&lowbar;redistribute 192&period;168&period;100&period;0&sol;24&NewLine; KerKer&commat;sw3&num;delete policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 from prefix-list-filter no&lowbar;redistribute exact<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">建立prefix-list包含三段Private IP &lpar;有的情況下也會將0&period;0&period;0&period;0&sol;0怡並做過濾&rpar;:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set policy-options prefix-list no&lowbar;redistribute 10&period;0&period;0&period;0&sol;8&NewLine; KerKer&commat;sw3&num;set policy-options prefix-list no&lowbar;redistribute 172&period;16&period;0&period;0&sol;12&NewLine; KerKer&commat;sw3&num;set policy-options prefix-list no&lowbar;redistribute 192&period;168&period;0&period;0&sol;16<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">套用至policy-statement的prefix-list-filter,並標記為orlonger:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&num;set policy-options policy-statement direct&lowbar;to&lowbar;ospf term 0 from prefix-list-filter no&lowbar;redistribute orlonger<&sol;code><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"wp-block-paragraph">policy-statement設定檔完成後大概會長這樣:<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-code"><code> KerKer&commat;sw3&gt&semi; show configuration policy-options policy-statement direct&lowbar;to&lowbar;ospf&NewLine; term 0 &lbrace;&NewLine; from &lbrace;&NewLine; prefix-list-filter no&lowbar;redistribute orlonger&semi;&NewLine; &rcub;&NewLine; then reject&semi;&NewLine; &rcub;&NewLine; term 1 &lbrace;&NewLine; from protocol direct&semi;&NewLine; then accept&semi;&NewLine; &rcub;&NewLine; term 2 &lbrace;&NewLine; then reject&semi;&NewLine; &rcub;<&sol;code><&sol;pre>&NewLine;

Exit mobile version