Routing Fundamentals · Topic 2 of 4

Route Preference and Routing Instances

Learn Junos route preference values and how to change them, plus routing instance types, configuration and tables, for the JNCIA-Junos JN0-106 exam.

  • 6 min
In a nutshell
  • Lowest preference wins: Direct and Local 0, Static 5, OSPF 10, IS-IS 15 and 18, RIP 100, Aggregate 130, OSPF external 150, IS-IS external 160 and 165, BGP 170.
  • Preference compares routes to the same prefix; longest match compares prefixes.
  • The default instance is master, with table inet.0.

What it is

Route preference is the value Junos OS uses to choose between routes to the same prefix learned from different sources. Each source has a default preference, and the lowest value wins. Other vendors call this administrative distance.

A routing instance is a separate routing table, with its own interfaces and routing settings, on the same device. Instances let one router keep traffic for different customers, services or departments apart.

Static routepreference 5compareOSPF routepreference 10lower winsStatic routeactive

How it works

Default route preferences

Route sourceDefault preference
Direct (connected subnet)0
Local (the interface's own address)0
Static5
OSPF internal10
IS-IS level 1 internal15
IS-IS level 2 internal18
RIP100
Aggregate130
OSPF AS external150
IS-IS level 1 external160
IS-IS level 2 external165
BGP (internal and external)170

Preference is a 32-bit value, from 0 to 4294967295. In show route it appears in brackets after the protocol, for example [OSPF/10] or [BGP/170].

If two routes to the same prefix have the same preference, Junos OS moves on to further tie-breakers, such as the protocol metric. For the JN0-106 exam, the key rule is simply that the lowest preference becomes the active route.

Changing preference

You can override the default for a protocol or a single route:

user@router# set protocols ospf preference 20
user@router# set protocols ospf external-preference 160
user@router# set protocols bgp preference 160
user@router# set routing-options static route 10.0.0.0/8 next-hop 10.1.1.2 preference 200

A static route with a higher preference than a dynamic route is a floating static route: it stays inactive while the dynamic route exists and becomes active only if the dynamic route disappears. The Static Routing page shows this with qualified-next-hop.

Preference and longest match work together

Preference never compares routes to different prefixes. The router first selects the active route for each prefix by preference, and then forwards each packet using the longest match among those active routes.

Routes tosame prefixlowest preferenceActive routeForwarding tablelongest matchPacketnext hop

Routing instances

Every Junos device has a default instance, called master, whose IPv4 table is inet.0. You add more instances under [edit routing-instances].

Instance typeUse
virtual-routerA separate routing table with its own interfaces and protocols, without VPN features
vrfA Layer 3 VPN instance on a provider edge router, with a route distinguisher and route targets
forwardingUsed with filter-based forwarding to send matched traffic using a different table; it has no interfaces of its own
virtual-switchA separate Layer 2 switching domain

Configuring a virtual router

user@router# set routing-instances VR1 instance-type virtual-router
user@router# set routing-instances VR1 interface ge-0/0/2.0
user@router# set routing-instances VR1 routing-options static route 0.0.0.0/0 next-hop 10.2.2.1
user@router# commit

The same in hierarchy form:

routing-instances {
    VR1 {
        instance-type virtual-router;
        interface ge-0/0/2.0;
        routing-options {
            static {
                route 0.0.0.0/0 next-hop 10.2.2.1;
            }
        }
    }
}

The interface ge-0/0/2.0 now belongs to VR1. Its Direct and Local routes, and the static default route, go into the table VR1.inet.0, not inet.0. An interface can belong to only one instance.

ge 0/0/2.0in VR1VR1.inet.0separate tablege 0/0/0.0in masterinet.0default table

Working with instances

CommandWhat it does
show route instanceLists the routing instances and their tables
show route table VR1.inet.0Shows the routes in VR1
ping 10.2.2.1 routing-instance VR1Pings using the VR1 table
traceroute 10.2.2.1 routing-instance VR1Traces using the VR1 table

Without the routing-instance option, ping and traceroute use the master instance and inet.0. Instances are isolated, so routes are not shared between them unless you configure that, for example with a static route that uses next-table.

A worked example

R1 learns 192.168.10.0/24 from OSPF and also has a static route to the same prefix through a backup link with preference 200. OSPF at 10 beats 200, so the OSPF route is active and the static route waits. When the OSPF neighbor fails, the OSPF route disappears and the static route becomes active.

The same router has a guest network on ge-0/0/2.0 in a virtual router called GUEST. show route table GUEST.inet.0 shows its own default route to the guest firewall, and nothing from inet.0, so guests cannot reach internal subnets.

How the exam asks about this

  • "What is the default preference of a static route?" → 5.
  • "OSPF and BGP both offer a route to the same prefix. Which is active by default?" → OSPF, preference 10 against BGP 170.
  • "Which instance type gives a separate routing table without VPN features?" → virtual-router.

Common mistakes

Thinking a higher preference wins. In Junos OS the lowest preference is preferred. A route with preference 5 beats one with 170.

Mixing up OSPF internal and external. OSPF internal routes are 10; OSPF AS external routes are 150. They are changed with preference and external-preference.

Forgetting the instance when testing. A plain ping uses inet.0. To test an address reachable only in VR1, add routing-instance VR1.

What to remember for the exam

  • Lowest preference wins: Direct and Local 0, Static 5, OSPF 10, IS-IS 15 and 18, RIP 100, Aggregate 130, OSPF external 150, IS-IS external 160 and 165, BGP 170.
  • Preference compares routes to the same prefix; longest match compares prefixes.
  • The default instance is master, with table inet.0.
  • A virtual router has its own table, named like VR1.inet.0, and its own interfaces.
  • Use routing-instance with ping and traceroute to test inside an instance.
Exam tip

For preference questions, write the protocols in a column with their numbers before you read the options. The exam often hides the trap in OSPF external at 150 or BGP at 170.

Check yourself

  • Which is preferred by default, an IS-IS level 2 internal route or a RIP route to the same prefix?

    The IS-IS level 2 internal route, because its preference of 18 is lower than RIP's 100.

  • What table holds the IPv4 routes of a virtual router named VR1?

    VR1.inet.0, separate from the master instance's inet.0.

  • What is a floating static route?

    A static route given a higher preference than a dynamic route, so it becomes active only when the dynamic route disappears.

Topic 2 of 4 in Routing Fundamentals

Test yourself on Routing Fundamentals

The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.