Navigation
Guide That Contains This Content
[+] Expand All
[-] Collapse All

    Example: Rejecting Known Invalid Routes

    This example shows how to create a routing policy that prevents known invalid routes from being accepted into a routing table. By default, Junos OS rejects known invalid routes (such as martian routes). This example shows how to implement an extra level of protection that takes effect when the default martian route policy is accidentally or intentionally overridden.

    Requirements

    No special configuration beyond device initialization is required before you configure this example.

    Overview

    In this example, you create a policy called rejectpolicy1 that rejects routes with a mask of /8 and greater (/8, /9, /10, and so on) that have the first 8 bits set to 0. This policy also accepts routes less than 8 bits in length by creating a mask of 0/0 up to /7.

    The example shows two devices in two different autonomous systems (ASs) with an external BGP (EBGP) peering session. Device R1 has multiple static routes configured and a routing policy that sends static routes through BGP. The static routes are as follows:

    user@R1# show routing-options
    static {route 0.0.0.0/8 reject;route 0.0.0.0/7 reject;route 0.0.0.0/0 reject;}

    Junos OS ordinarily ignores 0/8 and longer IP addresses. Therefore, to make this example work it is necessary to override the default behavior of Junos OS. To do this, both Device R1 and Device R2 require the following setting:

    user@R1(and on R2)# show routing-options
    rib inet.0 {martians {0.0.0.0/8 orlonger allow;}}

    This setting is required on both devices. Without this setting on Device R1, Device R1 does not send 0/8 and longer IP addresses to Device R2. With the setting on Device R1 but omitted on Device R2, Device R2 ignores incoming 0/8 and longer IP addresses.

    Topology

    Figure 1 shows the sample network.

    Figure 1: BGP Invalid Routes Topology

    BGP Invalid Routes Topology

    CLI Quick Configuration shows the configuration for all of the devices in Figure 1.

    The section Step-by-Step Procedure describes the steps on Device R2.

    Configuration

    CLI Quick Configuration

    To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

    Device R1

    set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30set interfaces lo0 unit 0 family inet address 192.168.0.1/32set protocols bgp group ext type externalset protocols bgp group ext export send-direct-and-staticset protocols bgp group ext peer-as 200set protocols bgp group ext neighbor 10.0.0.2set policy-options policy-statement send-direct-and-static term 1 from protocol directset policy-options policy-statement send-direct-and-static term 1 from protocol staticset policy-options policy-statement send-direct-and-static term 1 then acceptset routing-options rib inet.0 martians 0.0.0.0/8 orlonger allowset routing-options static route 0.0.0.0/8 rejectset routing-options static route 0.0.0.0/7 rejectset routing-options static route 0.0.0.0/0 rejectset routing-options autonomous-system 100

    Device R2

    set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30set interfaces lo0 unit 0 family inet address 192.168.0.2/32set protocols bgp group ext type externalset protocols bgp group ext import rejectpolicy1set protocols bgp group ext export send-directset protocols bgp group ext neighbor 10.0.0.1 peer-as 100set policy-options policy-statement rejectpolicy1 term rejectterm1 from route-filter 0.0.0.0/0 upto /7 acceptset policy-options policy-statement rejectpolicy1 term rejectterm1 from route-filter 0.0.0.0/8 orlonger rejectset policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset routing-options rib inet.0 martians 0.0.0.0/8 orlonger allowset routing-options autonomous-system 200

    Step-by-Step Procedure

    The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.

    To configure Device R2:

    1. Configure the device interfaces.
      [edit interfaces]user@R2# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30
      user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
    2. Configure the local autonomous system.
      [edit routing-options]user@R2# set autonomous-system 200
    3. Configure the routing policy that sends direct routes.
      [edit policy-options policy-statement send-direct term 1]user@R2# set from protocol directuser@R2# set then accept
    4. Add the disallowed 0/8 and longer martian routes to be installed in the IPv4 unicast routing table.
      [edit routing-options rib inet.0]user@R2# set martians 0.0.0.0/8 orlonger allow
    5. Configure a routing policy that specifies which routes to accept and which routes to reject.
      [edit policy-options policy-statement rejectpolicy1 term rejectterm1]user@R2# set from route-filter 0.0.0.0/0 upto /7 acceptuser@R2# set from route-filter 0.0.0.0/8 orlonger reject
    6. Configure the external peering with Device R2.
      [edit protocols bgp group ext]user@R2# set type externaluser@R2# set neighbor 10.0.0.1 peer-as 100
    7. Apply the routing policies.
      [edit protocols bgp group ext]user@R2# set import rejectpolicy1user@R2# set export send-direct

    Results

    From configuration mode, confirm your configuration by entering the show interfaces, show protocols, show policy-options, and show routing-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

    user@R2# show interfaces
    fe-1/2/0 {unit 0 {family inet {address 10.0.0.2/30;}}}
    lo0 {unit 0 {family inet {address 192.168.0.2/32;}}}
    user@R2# show protocols
    bgp {group ext {type external;import rejectpolicy1;export send-direct;neighbor 10.0.0.1 {peer-as 100;}}}
    user@R2# show policy-options
    policy-statement rejectpolicy1 {term rejectterm1 {from {route-filter 0.0.0.0/0 upto /7 accept;route-filter 0.0.0.0/8 orlonger reject;}}}
    policy-statement send-direct {term 1 {from protocol direct;then accept;}}
    user@R2# show routing-options
    rib inet.0 {martians {0.0.0.0/8 orlonger allow;}}
    autonomous-system 200;

    If you are done configuring the device, enter commit from configuration mode.

    Verification

    Confirm that the configuration is working properly.

    Verifying the Routes Sent from Device R2

    Purpose

    Make sure that Device R1 is sending the 0/8 prefix to Device R2.

    Action

    From operational mode, enter the show route advertising-protocol bgp command.

    user@R1> show route advertising-protocol bgp 10.0.0.2
    inet.0: 7 destinations, 8 routes (7 active, 0 holddown, 0 hidden)
      Prefix                  Nexthop              MED     Lclpref    AS path
    * 0.0.0.0/0               Self                                    I
    * 0.0.0.0/7               Self                                    I
    * 0.0.0.0/8               Self                                    I
    * 10.0.0.0/30             Self                                    I
    * 192.168.0.1/32          Self                                    I
    

    Meaning

    The output shows that Device R1 is sending all of the static routes, including the 0/8 routes, to Device R2.

    Checking Device R2’s Routing Table

    Purpose

    Make sure that the 0/0 and 0/7 prefixes are accepted, and the 0/8 route is rejected.

    Action

    From operational mode, enter the show route protocols bgp command.

    user@R2> show route protocol bgp
    inet.0: 7 destinations, 8 routes (6 active, 0 holddown, 1 hidden)
    + = Active Route, - = Last Active, * = Both
    
    0.0.0.0/0          *[BGP/170] 02:42:25, localpref 100
                          AS path: 100 I, validation-state: unverified
                        > to 10.0.0.1 via fe-1/2/0.0
    0.0.0.0/7          *[BGP/170] 02:42:25, localpref 100
                          AS path: 100 I, validation-state: unverified
                        > to 10.0.0.1 via fe-1/2/0.0
    10.0.0.0/30         [BGP/170] 1d 01:01:51, localpref 100
                          AS path: 100 I, validation-state: unverified
                        > to 10.0.0.1 via fe-1/2/0.0
    192.168.0.1/32     *[BGP/170] 1d 01:01:51, localpref 100
                          AS path: 100 I, validation-state: unverified
                        > to 10.0.0.1 via fe-1/2/0.0
    

    Meaning

    The output shows that on Device R2, the 0/0 and 0/7 routes are accepted into the routing table, and the 0/8 route is missing, as intended.

    Published: 2013-07-31