{"id":443,"date":"2015-11-26T17:01:44","date_gmt":"2015-11-26T17:01:44","guid":{"rendered":"http:\/\/www.mtin.net\/blog\/?p=443"},"modified":"2015-11-26T17:06:37","modified_gmt":"2015-11-26T17:06:37","slug":"how-does-bgp-select-which-route","status":"publish","type":"post","link":"https:\/\/www.mtin.net\/blog\/how-does-bgp-select-which-route\/","title":{"rendered":"How does BGP select which route?"},"content":{"rendered":"<p>BGP can be a complex and almost mystical protocol.  For those of you who are trying to determine how BGP selects which route here is your guide.  Before we get into it a couple of things to keep in mind.  First, BGP is not a multipath routing protocol.  This is different than what you may be used to with OSPF.  BGP goes to great lengths to encure only one route is used. Secondly, there are some vendor specific rules which are applied. I will try to point those out as we go along. <\/p>\n<p>1.The first test is if the next hop router is accessible.<\/p>\n<p>2.If Synchronization is enabled, the router will ignore any iBGP routes which are not synced.<\/p>\n<p>3.The third is Cisco specific. Cisco uses a weight attribute. The largest weight wins. Default weight is zero. Maximum weight is 65,535.<\/p>\n<p>4.If the weights are the same, the highest local preference is chosen from LOCAL_PREF. It&#8217;s important to note that routers only receive this from iBGP.  <\/p>\n<p>5.Net up, the router checks to see if any of the possible routes were originated locally. The two main checks are either the <em>network<\/em> or <em>aggregate<\/em> commands. The network command wins if it is originated locally.<\/p>\n<p>6.If two or more routes are still equal the router looks as AS_PATH. The router will prefer any iBGP routes. Outside of the AS BGP will prefer the shortest path.<\/p>\n<p>7.BGP then moves on to the ORIGIN attribute.  If the path lengths are the same, BGP selects IGP over EGP and EGP over INCOMPLETE routes.<\/p>\n<p>8.BGP now looks at MED values. The lowest value is selected. Note, MED is only used if both routes are received from the same AS, or if always-compare-med has been enabled.  Be careful with always-compare-meds as this can cause routing loops.<\/p>\n<p>9.BGP will then prefer eBGP to iBGP routes.  This is not the same as #5 above. Only external routes are looked at here.<\/p>\n<p>10.Next IBGP costs are compared to the next hop routers.  The closest one is selected.<\/p>\n<p>11.Ages of routes are finally connected.  This is kind of like choosing teams for dodgeball. The oldest route wins.  The reason being is oldest routes are thought to be more stable.<\/p>\n<p>12.And finally, if all else fails the router with the lowest router ID wins.<\/p>\n<p>This is a quick low-down on how BGP &#8220;thinks&#8221; in order to determine routes.  If anyone has some Cisco, Mikrotik, quagga, or other specific attributes please comment.  I have reached out to Mikrotik and Ubiquiti specifically to see if this is in-line with their implementation of BGP.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BGP can be a complex and almost mystical protocol. For those of you who are trying to determine how BGP selects which route here is your guide. Before we get into it a couple of things to keep in mind. First, BGP is not a multipath routing protocol. This is different than what you may [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[212,17],"tags":[259,13,261,258,262,260,15],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6VLMf-79","jetpack-related-posts":[{"id":452,"url":"https:\/\/www.mtin.net\/blog\/rfcs-you-need-to-know-rfc-2796-bgp-route-reflection\/","url_meta":{"origin":443,"position":0},"title":"RFC&#8217;s you need to know: RFC 2796 BGP Route Reflection","author":"j2sw","date":"November 29, 2015","format":false,"excerpt":"https:\/\/tools.ietf.org\/html\/rfc2796 Currently in the Internet, BGP deployments are configured such that all BGP speakers within a single AS must be fully meshed and any external routing information must be re-distributed to all other routers within that AS. For n BGP speakers within an AS that requires to maintain n*(n-1)\/2 unique\u2026","rel":"","context":"In &quot;BGP&quot;","block_context":{"text":"BGP","link":"https:\/\/www.mtin.net\/blog\/category\/networking\/bgp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2267,"url":"https:\/\/www.mtin.net\/blog\/what-is-a-bgp-confederation\/","url_meta":{"origin":443,"position":1},"title":"What is a BGP Confederation?","author":"j2sw","date":"May 15, 2018","format":false,"excerpt":"In\u00a0network routing,\u00a0BGP confederation\u00a0is a method to use\u00a0Border Gateway Protocol\u00a0(BGP) to subdivide a single\u00a0autonomous system\u00a0(AS) into multiple internal sub-AS's, yet still advertise as a single AS to\u00a0external peers. This is done to reduce the number of entries in the iBGP routing table.\u00a0 If you are familiar with breaking OSPF domains up\u2026","rel":"","context":"In \"BGP\"","block_context":{"text":"BGP","link":"https:\/\/www.mtin.net\/blog\/tag\/bgp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":183,"url":"https:\/\/www.mtin.net\/blog\/bgp-lockdown-hints\/","url_meta":{"origin":443,"position":2},"title":"BGP lockdown hints","author":"j2sw","date":"September 29, 2014","format":false,"excerpt":"As I am preparing talks for the upcoming WISPAPALOOZA 2014 in Las Vegas I am making some notes on advanced BGP. \u00a0If you are running BGP, and want to lock it down a little here are some general hints. \u00a0If you want more attend my session in Vegas or look\u2026","rel":"","context":"In &quot;Mikrotik&quot;","block_context":{"text":"Mikrotik","link":"https:\/\/www.mtin.net\/blog\/category\/mikrotik\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":132,"url":"https:\/\/www.mtin.net\/blog\/mtin-services\/","url_meta":{"origin":443,"position":3},"title":"MTIN Services","author":"j2sw","date":"August 26, 2014","format":false,"excerpt":"WISP and Wireline\/Fiber Design and Operation MPLS Design and Implementation Multicast Routing IGMP, PIM eBGP\/iBGP design\/implementation Cisco Routers 2800, 3600, 7200, 7600, ASR, ISR Cisco Switches 2950, 3550, 3560, 3750, 6500 Switching (Layer 2) STP, RSTP, EOIP, MSTP, VLAN \u2013 dot1q and q-in-q Routing (layer 3) OSPF, BGP, MPLS, L2VPN\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2670,"url":"https:\/\/www.mtin.net\/blog\/bgp-monitoring-rfc-7854\/","url_meta":{"origin":443,"position":4},"title":"BGP Monitoring RFC 7854","author":"j2sw","date":"December 4, 2018","format":false,"excerpt":"https:\/\/tools.ietf.org\/html\/rfc7854 This document defines the BGP Monitoring Protocol (BMP), which can be used to monitor BGP sessions. BMP is intended to provide a convenient interface for obtaining route views. Prior to the introduction of BMP, screen scraping was the most commonly used approach to obtaining such views. The design goals\u2026","rel":"","context":"In &quot;BGP&quot;","block_context":{"text":"BGP","link":"https:\/\/www.mtin.net\/blog\/category\/networking\/bgp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.mtin.net\/blog\/wp-content\/uploads\/2018\/05\/atasco.jpg?fit=1122%2C711&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":365,"url":"https:\/\/www.mtin.net\/blog\/basic-mikrotik-bgp-filter-rules\/","url_meta":{"origin":443,"position":5},"title":"Basic Mikrotik BGP filter rules","author":"j2sw","date":"October 29, 2015","format":false,"excerpt":"Below are some basic Filter Rules for Mikrotik BGP filtering. \u00a0These are not complex and can be very easily implemented on your BGP peers. Before we get to the code there are a few assumptions 1.Your own IP space in this example is 1.1.1.0\/22 2.These filters are not fancy and\u2026","rel":"","context":"In &quot;Mikrotik&quot;","block_context":{"text":"Mikrotik","link":"https:\/\/www.mtin.net\/blog\/category\/mikrotik\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/posts\/443"}],"collection":[{"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/comments?post=443"}],"version-history":[{"count":2,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":445,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions\/445"}],"wp:attachment":[{"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mtin.net\/blog\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}