Related Documentation
- ACX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- J Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- M Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- MX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- PTX Series
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- QFX Series
- Route Filter Match Conditions
- SRX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- T Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
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:
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:
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

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
Device R2
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:
- 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 - Configure the local autonomous system.[edit routing-options]user@R2# set autonomous-system 200
- 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
- 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
- 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
- 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
- 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.
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.2inet.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 bgpinet.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.
Related Documentation
- ACX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- J Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- M Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- MX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- PTX Series
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- QFX Series
- Route Filter Match Conditions
- SRX Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions
- T Series
- Understanding Martian Addresses
- Example: Configuring Martian Addresses
- Route Filter Match Conditions