July 13, 2016
This post contains notes about BGP operation and configuration.
- A router stores all learned BGP prefixes and PAs in its BGP table (except for any prefixes filtered by an inbound BGP filter).
- The router advertises only the best route for each prefix.
- If the best path in BGP table is not put inside routing table (for example it has higher administrative distance than a static route) then it is still advertised to all BGP peers (contrary to what most other distance-vector routing protocols do); you can change that behavior with bgp suppress-inactive option.
- When a router learns routes from an iBGP peer, that router does not advertise the
same routes to another iBGP peer
- BGP Router-ID: explicity configured; or highest loopback; or highest other interface. In most configuration/verification commands you will see the neighbor IP address (not neighbor Router-ID).
- BGP Router-IDs have to be different to create neighborhood.
- BGP uses tcp (port 179)
- BGP states – among others:
- idle – the BGP process is down or awaiting the next try
- active – the tcp connection is established
- established (or the number) – the peers exchange Update messages
- Administrative distance: eBGP = 20; iBGP = 200
The following snippet shows basic BGP configuration.
komo-r001#show run | section bgp router bgp 65025 bgp log-neighbor-changes neighbor 172.16.135.2 remote-as 65135 neighbor 172.16.135.2 password cisco
komo-r001#show ip bgp summary BGP router identifier 172.16.135.1, local AS number 65025 BGP table version is 5, main routing table version 5 4 network entries using 576 bytes of memory 4 path entries using 320 bytes of memory 1/1 BGP path/bestpath attribute entries using 136 bytes of memory 1 BGP AS-PATH entries using 24 bytes of memory 0 BGP route-map cache entries using 0 bytes of memory 0 BGP filter-list cache entries using 0 bytes of memory BGP using 1056 total bytes of memory BGP activity 4/0 prefixes, 4/0 paths, scan interval 60 secs Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 172.16.135.2 4 65135 86 58 5 0 0 00:48:53 4
komo-r001#show ip bgp neighbors BGP neighbor is 172.16.135.2, remote AS 65135, external link BGP version 4, remote router ID 172.16.135.2 BGP state = Established, up for 00:49:15 Last read 00:00:26, last write 00:00:41, hold time is 180, keepalive interval is 60 seconds Neighbor sessions: 1 active, is not multisession capable (disabled) (...)
komo-r001#show tcp brief TCB Local Address Foreign Address (state) 67BC3198 172.16.135.1.59226 172.16.135.2.179 ESTAB
Restart all BGP neighbor relationships
komo-r001#clear ip bgp * *Jul 13 23:28:01.787: %BGP-5-ADJCHANGE: neighbor 172.16.135.2 Down User reset *Jul 13 23:28:01.787: %BGP_SESSION-5-ADJCHANGE: neighbor 172.16.135.2 IPv4 Unicast topology base removed from session User reset komo-r001# *Jul 13 23:28:02.883: %BGP-5-ADJCHANGE: neighbor 172.16.135.2 Up komo-r001#
You can shutdown communication with neighbor:
router bgp 65025 neighbor 172.16.135.2 shutdown // no neighbor 172.16.135.2 shutdown
BGP Table veryfication
komo-r001#show ip bgp // lists the entirety of the BGP routing table BGP table version is 5, local router ID is 172.16.135.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.10.10.179/32 172.16.135.2 0 0 65135 ? *> 10.112.208.0/24 172.16.135.2 0 0 65135 ? *> 10.112.209.0/24 172.16.135.2 0 0 65135 ? r> 172.16.135.0/30 172.16.135.2 0 0 65135 ?
Note for r> – it means that the BGP route cannot be inserted into the IP routing table (in this case there is a static route for the same prefix with a lower admin distance).
komo-r001#show ip bgp rib-failure Network Next Hop RIB-failure RIB-NH Matches 172.16.135.0/30 172.16.135.2 Higher admin distance n/a
show ip bgp prefix [subnet-mask] // List possible routes, per prefix. show ip bgp neighbors ip-address received-routes // routes learned from one neighbor (before inbound filtering) show ip bgp neighbors ip-address routes // routes learned from one neighbor (after inbound filtering) show ip bgp neighbors ip-address advertised-routes // routes advertised to a neighbor (after outbound filtering) show ip bgp summary // number of prefixes learned per neighbor show ip bgp IP/MASK_LENGTH long-prefixes // display route for IP/MASK_LENGTH and all more specific routes show ip bgp neighbor neighbor-id advertised-routes // shows the post-filter BGP updates (sent to the neighbor) show ip bgp neighbor received-routes // shows the pre-filter BGP updates (it requires neighbor soft-reconfiguration inbound subcommand - the router to retain the received BGP Updates from that neighbor [extra memory used]). show ip bgp neighbors neighbor-id routes // show the post-filter BGP updates
You can inject routes into BGP table using network Prefix Mask command. – If exactly the same entry (Prefix, Mask) exists in the IP routing table; then this prefix is injected into local BGP table (and advertised to the other BGP peers). Note – this behavior differs if BGP auto-summary is configured.
You can also use redistribute command to inject routes learned from an IGP (ex: OSPF). This command can also be used to inject static or connected routes into BGP table.
router bgp 65025 redistribute connected
You can perform either hard or soft reset of BGP relationship with neighbor (for example, in order to apply new in/out BGP update filters). Hard reset tears down tcp connection and build the relationship from scratch. Soft reset does not kill the BGP neighborhood but resend outgoing updates, reprocess incoming updates (using applied in/out filters). In both cases you can use specific variations of clear command. For example:
clear ip bgp * // hard reset for all neighbors clear ip bgp neighbor-id soft out // soft reset for one neighbor for out-update direction only