Resources
    Configuring BGP Local Pre ...
    14 June 22

    Configuring BGP Local Preference on Juniper Routers

    Posted byRohit Pardasani (CCIE# 21282)
    facebooktwitterlinkedin
    news-featured

    In the BGP Path selection algorithm, if your device is not a Cisco router, the first BGP Path Attribute considered during Path Selection is the Local Preference attribute.

    Local Preference is not a vendor-specific BGP Path Attribute, unlike the WEIGHT attribute, which is Cisco Proprietary.

    The Local Preference attribute can be modified to allow a specific external BGP path to be chosen when you have a multi-homed environment. Local Preference can be applied inbound from an external BGP neighbor or outbound to an internal BGP neighbor. Local Preference shows the best outbound interface towards another AS. In other words, here, it shows the exit point of your AS towards another AS.

    The default value of Local Preference is 100. And always, the highest one is chosen as the Best BGP path. Local Preference is a non-transitive attribute as it cannot be advertised to an external BGP neighbor. 

    The local Preference attribute is a Well-known and Discretionary BGP Path Attribute. As we mentioned before, it is supported by every BGP implementation (well-known), and every BGP router recognizes it but is optionally present in the BGP Update packet (discretionary). Since Local Preference is a Well-known attribute, it must be understood by all BGP implementations irrespective of a vendor. Since Local Preference is discretionary, it may or may not be present as a mandatory option.

    Let's now see how to configure Local Preference on a Juniper Router.

    Here is my topology:

    Topography Neighborships.png


    In this topology, I have already pre-configured my BGP neighborships. Here is my pre-config:

    vMXvCP-1:
    cli
    configure
    set routing-options router-id 1.1.1.1
    set routing-options autonomous-system 1
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.12.2 peer-as 2345
    set protocols bgp group eBGP neighbor 192.168.13.3 peer-as 2345
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 1.1.1.1/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    commit

    vMXvCP-2:
    cli
    configure
    set routing-options router-id 2.2.2.2
    set routing-options autonomous-system 2345
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.12.1 peer-as 1
    set protocols bgp group iBGP type internal
    set protocols bgp group iBGP peer-as 2345
    set protocols bgp group iBGP local-address 2.2.2.2
    set protocols bgp group iBGP neighbor 7.7.7.7  
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 2.2.2.2/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    set policy-options policy-statement NHS term 1 from protocol bgp
    set policy-options policy-statement NHS term 1 from route-type external
    set policy-options policy-statement NHS term 1 then next-hop self
    set protocols bgp group iBGP export NHS
    set protocols bgp group iBGP export ADVERTISE_ROUTES
    set protocols bgp advertise-inactive
    commit

    vMXvCP-3:
    cli
    configure
    set routing-options router-id 3.3.3.3
    set routing-options autonomous-system 2345
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.13.1 peer-as 1
    set protocols bgp group iBGP type internal
    set protocols bgp group iBGP peer-as 2345
    set protocols bgp group iBGP local-address 3.3.3.3
    set protocols bgp group iBGP neighbor 7.7.7.7
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 3.3.3.3/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    set policy-options policy-statement NHS term 1 from protocol bgp
    set policy-options policy-statement NHS term 1 from route-type external
    set policy-options policy-statement NHS term 1 then next-hop self
    set protocols bgp group iBGP export NHS
    set protocols bgp group iBGP export ADVERTISE_ROUTES
    set protocols bgp advertise-inactive
    commit

    vMXvCP-4:
    cli
    configure
    set routing-options router-id 4.4.4.4
    set routing-options autonomous-system 2345
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.46.6 peer-as 6
    set protocols bgp group iBGP type internal
    set protocols bgp group iBGP peer-as 2345
    set protocols bgp group iBGP local-address 4.4.4.4
    set protocols bgp group iBGP neighbor 7.7.7.7
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 4.4.4.4/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    set policy-options policy-statement NHS term 1 from protocol bgp
    set policy-options policy-statement NHS term 1 from route-type external
    set policy-options policy-statement NHS term 1 then next-hop self
    set protocols bgp group iBGP export NHS
    set protocols bgp group iBGP export ADVERTISE_ROUTES
    set protocols bgp advertise-inactive
    commit

    vMXvCP-5:
    cli
    configure
    set routing-options router-id 5.5.5.5
    set routing-options autonomous-system 2345
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.56.6 peer-as 6
    set protocols bgp group iBGP type internal
    set protocols bgp group iBGP peer-as 2345
    set protocols bgp group iBGP local-address 5.5.5.5
    set protocols bgp group iBGP neighbor 7.7.7.7
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 5.5.5.5/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    set policy-options policy-statement NHS term 1 from protocol bgp
    set policy-options policy-statement NHS term 1 from route-type external
    set policy-options policy-statement NHS term 1 then next-hop self
    set protocols bgp group iBGP export NHS
    set protocols bgp group iBGP export ADVERTISE_ROUTES
    set protocols bgp advertise-inactive
    commit

    vMXvCP-6:
    cli
    configure
    set routing-options router-id 6.6.6.6
    set routing-options autonomous-system 6
    set protocols bgp export ADVERTISE_ROUTES
    set protocols bgp group eBGP type external
    set protocols bgp group eBGP neighbor 192.168.46.4 peer-as 2345
    set protocols bgp group eBGP neighbor 192.168.56.5 peer-as 2345
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from protocol direct
    set policy-options policy-statement ADVERTISE_ROUTES term 1 from route-filter 6.6.6.6/32 exact
    set policy-options policy-statement ADVERTISE_ROUTES term 1 then accept
    commit

    vMXvCP-RR:
    set routing-options router-id 7.7.7.7
    set routing-options autonomous-system 2345
    set protocols bgp group iBGP local-address 7.7.7.7
    set protocols bgp group iBGP cluster 7.7.7.7
    set protocols bgp group iBGP peer-as 2345
    set protocols bgp group iBGP neighbor 2.2.2.2
    set protocols bgp group iBGP neighbor 3.3.3.3
    set protocols bgp group iBGP neighbor 4.4.4.4
    set protocols bgp group iBGP neighbor 5.5.5.5
    set protocols bgp advertise-inactive
    commit

    Based on my configs above: 

    1. vMXvCP-1 establishes an external BGP neighborship with vMXvCP-2 and vMXvCP-3. 

    2. vMXvCP-6 establishes an external BGP neighborship with vMXvCP-4 and vMXvCP-5. 

    3. vMXvCP-RR establishes an internal BGP neighborship with vMXvCP-2, vMXvCP-3, vMXvCP-4, and vMXvCP-5.

    Currently, without any Local Preference configuration changes, vMXvCP-6 is seeing a default Local Preference of 100 and is choosing vMXvCP-4 as the primary exit for reaching the Loopback (1.1.1.1/32) of vMXvCP-1 based on some other BGP path selection attribute.

    root@vMX-6# run show route protocol bgp 1.1.1.1 detail    

    inet.0: 12 destinations, 18 routes (12 active, 0 holddown, 0 hidden)

    1.1.1.1/32 (2 entries, 1 announced)

            *BGP    Preference: 170/-101

                    Next hop type: Router, Next hop index: 590

                    Address: 0xcee9e30

                    Next-hop reference count: 8

                    Source: 192.168.46.4

                    Next hop: 192.168.46.4 via ge-0/0/2.0, selected

                    Session Id: 0x141

                    State: <Active Ext>

                    Local AS:     6 Peer AS:  2345

                    Age: 3:59

                    Validation State: unverified

                    Task: BGP_2345.192.168.46.4+54892

                    Announcement bits (1): 0-KRT

                    AS path: 2345 1 I

                    Accepted

                    Localpref: 100

                    Router ID: 4.4.4.4

             BGP    Preference: 170/-100

                    Next hop type: Router, Next hop index: 589

                    Address: 0xcee9d10

                    Next-hop reference count: 9

                    Source: 192.168.56.5

                    Next hop: 192.168.56.5 via ge-0/0/0.0, selected

                    Session Id: 0x140

                    State: <Ext>

                    Inactive reason: Local Preference

                    Local AS:     6 Peer AS:  2345

                    Age: 44

                    Validation State: unverified

                    Task: BGP_2345.192.168.56.5+179

                    AS path: 2345 1 I

                    Accepted

                    Localpref: 100

                    Router ID: 5.5.5.5

    Now let's go and configure local preference on VMXvCP-6 to ensure that vMXvCP-5 is chosen as the primary path to reach the Loopback (1.1.1.1/32) of vMXvCP-1. 

    vMXvCP-6:
    cli
    configure
    set protocols bgp group eBGP neighbor 192.168.56.5 import LP_FROM_R5
    set policy-options policy-statement LP_FROM_R5 term 1 from protocol bgp
    set policy-options policy-statement LP_FROM_R5 term 1 from route-filter 1.1.1.1/32 exact
    set policy-options policy-statement LP_FROM_R5 term 1 then local-preference 101
    commit

    As you can see above, I configured VMXvCP-6. I applied the policy statement inbound from the external BGP neighbor vMXvCP-5 as Local Preference cannot be configured on vMXvCP-5 outbound to vMXvCP-6 as Local Preference is non-transitive.

    This configuration results in VMXvCP-6 now preferring VMXvCP-5 as the primary exit router to reach 1.1.1.1/32. No changes were made in any other routers.

    root@vMX-6# run show route protocol bgp 1.1.1.1 detail    

    inet.0: 12 destinations, 18 routes (12 active, 0 holddown, 0 hidden)

    1.1.1.1/32 (2 entries, 1 announced)

            *BGP    Preference: 170/-100

                    Next hop type: Router, Next hop index: 589

                    Address: 0xcee9d10

                    Next-hop reference count: 9

                    Source: 192.168.56.5

                    Next hop: 192.168.56.5 via ge-0/0/0.0, selected

                    Session Id: 0x140

                    State: <Ext>

                    Inactive reason: Local Preference

                    Local AS:     6 Peer AS:  2345

                    Age: 44

                    Validation State: unverified

                    Task: BGP_2345.192.168.56.5+179

                    AS path: 2345 1 I

                    Accepted

                    Localpref: 101

                    Router ID: 5.5.5.5

            BGP    Preference: 170/-101

                    Next hop type: Router, Next hop index: 590

                    Address: 0xcee9e30

                    Next-hop reference count: 8

                    Source: 192.168.46.4

                    Next hop: 192.168.46.4 via ge-0/0/2.0, selected

                    Session Id: 0x141

                    State: <Active Ext>

                    Local AS:     6 Peer AS:  2345

                    Age: 3:59

                    Validation State: unverified

                    Task: BGP_2345.192.168.46.4+54892

                    Announcement bits (1): 0-KRT

                    AS path: 2345 1 I

                    Accepted

                    Localpref: 100

                    Router ID: 4.4.4.4

    I hope this was informative, and thank you.

    You can learn more about Juniper Routers with INE Networking courses! INE offers a monthly and annual subscription that allows you to develop your fundamental knowledge of Networking, Cyber Security, Cloud, and Data Science, as well as a Premium plan that provides more advanced learning courses. All INE plans include hands-on components and prepare you for your IT career. Check out more of how INE can help you!


    About INE
    INE is the premier provider of technical training for the IT industry. INE is revolutionizing the digital learning industry through the implementation of adaptive technologies and a proven method of hands-on training experiences. Our portfolio of training is built for all levels of technical learning, specializing in advanced networking technologies, next generation security and infrastructure programming and development. Want to talk to a training advisor about our course offerings and training plans? Give us a call at 877-224-8987 or email us at sales@ine.com.

    Topography Neighborships.png

    Topography Neighborships.png

    © 2024 INE. All Rights Reserved. All logos, trademarks and registered trademarks are the property of their respective owners.
    instagram Logofacebook Logotwitter Logolinkedin Logoyoutube Logo