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

邊做邊學,順便留個筆記,若有錯誤請不吝指教。

Junos基本操作及root密碼設定可參考我之前的文章:Juniper Junos基本操作、root密碼設定

所有Juniper相關文章列表:Juniper JunOS 系列文章列表

關於OSPF的基本設定可以參考:Junos動態路由OSPF基本設定

OSPF提供了將外部路由加入OSPF網路作路由交換的功能,這裡以將Direct link的路由轉送到OSPF網路為例。

架構圖與基本設定時使用的架構相同,且已經先將所有介面(除irb.100、irb.200外)加入OSPF area 0.0.0.0 中了。

首先要建立一個policy-statement作為路由會匯入的規則,只要是來自protocol direct的路由就都轉送到OSPF。

    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 1 from protocol direct
    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 1 then accept
    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 2 then reject

policy-statement設定檔完成後大概會長這樣:

    KerKer@sw3> show configuration policy-options policy-statement direct_to_ospf                   
    term 1 {
        from protocol direct;
        then accept;
    }
    term 2 {
        then reject;
    }

將剛剛設定好的policy-statement套用到OSPF的export上:

    KerKer@sw3#set protocols ospf export direct_to_ospf

可以透過在命令模式下show ospf database來確認是否有成功匯入外部路由:

    KerKer@sw3> show ospf database 
    ...
    OSPF AS SCOPE link state database
    Type    ID              Adv Rtr     Seq         Age     Opt     Cksum   Len 
    Extern  192.168.100.0   10.0.0.3    0x80000001  474     0x22    0x9245  36
    Extern  192.168.200.0   10.0.0.3    0x80000001  474     0x22    0x4231  36

如果不想匯入某些路由,可以在policy-statement作過濾,這裡以過濾掉192.168.100.0/24為例,在原本的policy-statement中加入一個新的term作過濾:

    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 0 from route-filter 192.168.100.0/24 exact
    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 0 then reject
    KerKer@sw3#insert policy-statement direct_to_ospf term 0 before term 1 

policy-statement設定檔完成後大概會長這樣:

    KerKer@sw3> show configuration policy-options policy-statement direct_to_ospf
    term 0 {
        from {
            route-filter 192.168.100.0/24 exact;
        }
        then reject;
    }
    term 1 {
        from protocol direct;
        then accept;
    }
    term 2 {
        then reject;
    }

這裡提一下route-filter後接的exact代表遮罩長度要與設定的prefix相同,在我們的例子中就是24,其他還有longer、orlonger、prefix-length-range等用來判斷prefix遮罩長度的作法。

查看ospf database確認是否成功過濾:

    KerKer@sw3> show ospf database 
    ...
    OSPF AS SCOPE link state database
    Type    ID              Adv Rtr     Seq         Age     Opt     Cksum   Len 
    Extern  192.168.200.0   10.0.0.3    0x80000001  474     0x22    0x4231  36

除了使用route-filter作過濾外,也可以引入prefix-list作過濾,這裡先將剛剛作的route-filter刪除。

    KerKer@sw3#delete policy-options policy-statement direct_to_ospf term 0 from route-filter 192.168.100.0/24 exact

新增一個prefix-list包含不匯入的路由,並在policy-statement中設定prefix-list-filter:

    KerKer@sw3#set policy-options prefix-list no_redistribute 192.168.100.0/24
    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 0 from prefix-list-filter no_redistribute exact

policy-statement設定檔完成後大概會長這樣,這樣作的效果與剛剛使用route-filter的效果是一致的:

    KerKer@sw3> show configuration policy-options policy-statement direct_to_ospf
    term 0 {
        from {
            prefix-list-filter no_redistribute exact;
        }
        then reject;
    }
    term 1 {
        from protocol direct;
        then accept;
    }
    term 2 {
        then reject;
    }

最後分享一下實務上常用到的,將Private IP的路由過濾掉不匯入OSPF的做法。

一樣先將剛剛作的設定刪除:

    KerKer@sw3#delete policy-options prefix-list no_redistribute 192.168.100.0/24
    KerKer@sw3#delete policy-options policy-statement direct_to_ospf term 0 from prefix-list-filter no_redistribute exact

建立prefix-list包含三段Private IP (有的情況下也會將0.0.0.0/0怡並做過濾):

    KerKer@sw3#set policy-options prefix-list no_redistribute 10.0.0.0/8
    KerKer@sw3#set policy-options prefix-list no_redistribute 172.16.0.0/12
    KerKer@sw3#set policy-options prefix-list no_redistribute 192.168.0.0/16

套用至policy-statement的prefix-list-filter,並標記為orlonger:

    KerKer@sw3#set policy-options policy-statement direct_to_ospf term 0 from prefix-list-filter no_redistribute orlonger

policy-statement設定檔完成後大概會長這樣:

    KerKer@sw3> show configuration policy-options policy-statement direct_to_ospf
    term 0 {
        from {
            prefix-list-filter no_redistribute orlonger;
        }
        then reject;
    }
    term 1 {
        from protocol direct;
        then accept;
    }
    term 2 {
        then reject;
    }

在〈[Juniper] Junos動態路由OSPF路由重分發(redistribute route)〉中有 1 則留言

  1. 自動引用通知: [Juniper] Junos動態路由OSPF基本設定 – KerKer 的模組世界

留言功能已關閉。