Course contents

Module 4: BGP PolicyLesson 4.9 (9 of 9 in this module)31 of 46 in the BGP course

Lab: filter the ISPs, tag with communities, stop transit

A provider can send you anything, and anything you send back to the other provider may be passed on. This lab puts a filter on what comes in, a tag on what you learned, and a block on what goes out, so the company cannot become a path between the two ISPs.

Advanced · 20 min read

You'll learn to filter received prefixes with a prefix list and route map, tag routes with a community, match the tag in an outbound route map, and prove each step with received-routes, advertised-routes and the community table.

The goal

You are working on the course network from the first lab. R1 peers with ISP A at 192.0.2.1 and R2 peers with ISP B at 192.0.2.5. In this lab you control both ISPs, and ISP A is misbehaving on purpose: besides 203.0.113.0/24, its customer network, it also sends 10.99.0.0/16, which is a private range that should not appear on the Internet, and a default route. ISP B sends only 203.0.113.0/24.

By the end you will have three results. R1 refuses the private prefix. Every route learned from a provider carries a community that says so. R2 refuses to send any provider-tagged route to ISP B, which stops the company becoming a transit network.

Diagram
The filtering lab: what each policy does and where it sits
The filtering lab: what each policy does and where it sits
The filtering lab: what each policy does and where it sitsAlong the top, ISP A connects to R1, R1 connects to R2 over iBGP and R2 connects to ISP B. Under the ISP A link, the inbound route map on R1 drops private prefixes and tags the rest with community 64500:100. Under the iBGP link, R1 sends the community to R2. Under the ISP B link, the outbound route map on R2 refuses anything tagged as learned from a provider, so the company never carries traffic between the two ISPs.ISP AAS 64501R110.255.0.1R210.255.0.2ISP BAS 64502R1 inbounddrop private prefixestag 64500:100R1 to R2, iBGPsend-communitykeeps the tagR2 outboundrefuse 64500:100and 64500:200ISP A routes never reach ISP B: no transit

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Filter on the way in, tag what you learned, and refuse the tagged routes on the way out. The tag is what lets R2 know a route came from a provider.
Diagram
Three results and how each is proved
Three results and how each is proved
ResultMechanismProof
The private prefix is refusedInbound route map on R1 with a deny clauseshow ip bgp 10.99.0.0 says not in table
Provider routes carry a tagSet community in the inbound permit clauseshow ip bgp community 64500:100
No provider route goes to the other ISPOutbound route map on R2 matching the tagsadvertised-routes lists only 198.51.100.0/24
Each result has its own check. A result with no check is a belief, not a fact.

Step 1: see what the provider sends

You cannot fix what you cannot see. Turn on soft reconfiguration for ISP A so R1 keeps an unfiltered copy, then ask for it.

router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 soft-reconfiguration inbound end clear ip bgp 192.0.2.1 soft in

R1. soft-reconfiguration inbound stores the routes ISP A sends before any inbound policy. The clear asks ISP A to send them again so the copy is filled.

Example output written for this lesson, not a router capture
R1#show ip bgp neighbors 192.0.2.1 received-routes
     Network          Next Hop            Metric LocPrf Weight Path
     0.0.0.0          192.0.2.1                0             0 64501 i
     10.99.0.0/16     192.0.2.1                0             0 64501 i
     203.0.113.0      192.0.2.1                0             0 64501 i

Total number of prefixes 3
Three prefixes. 203.0.113.0/24 is expected. 10.99.0.0/16 is a private range and should not come from a provider. The default route is acceptable for this company, so you will keep it.
Diagram
Seeing what the provider sent
Seeing what the provider sent

Turn on soft reconfiguration, ask ISP A to send its routes again, read received-routes, and pick out the prefix that should not be there.

  1. Enablesoft-reconfiginbound
  2. Refreshclear ip bgpsoft in
  3. Readreceived-routes,three prefixes
  4. Markthe privateprefix is wrong
received-routes only has something to show after soft reconfiguration has stored the copy.

Step 2: filter and tag on the way in

The route map has two clauses. The first, with deny, catches private prefixes and removes them. The second has no match line, so it matches everything left, and it sets a community. The tag 64500:100 is the company's own convention in this lab: first number the company AS, second number meaning "learned from ISP A". R2 will use 64500:200 for ISP B.

ip prefix-list BOGONS seq 5 permit 10.0.0.0/8 le 32 ip prefix-list BOGONS seq 10 permit 172.16.0.0/12 le 32 ip prefix-list BOGONS seq 15 permit 192.168.0.0/16 le 32 ! route-map FROM-ISPA deny 10 match ip address prefix-list BOGONS route-map FROM-ISPA permit 20 set community 64500:100 ! router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 route-map FROM-ISPA in neighbor 10.255.0.2 send-community end clear ip bgp 192.0.2.1 soft in

R1. The prefix list says which prefixes count as private: the permit lines here are matches, and the deny in the route map is what removes them. send-community makes R1 pass the tag to R2 over iBGP.

Notice the pair of words that confuse many learners. In a prefix list, permit means "this prefix matches". In the route map, deny means "a route that matches is dropped". The two work together, and neither one alone drops a route.

Diagram
Who says drop: the list or the route map
Who says drop: the list or the route map

A prefix list only says which prefixes match. The route map clause that uses the list says what happens to a match, and a deny clause drops it.

Prefix listpermit meansthis prefix matchesit drops nothing
Route map clausedeny means a matchis droppedpermit means kept
A permit line in the list plus a deny clause in the route map is how a prefix is dropped.

Configure R2 the same way for ISP B at 192.0.2.5. Use route-map FROM-ISPB permit 20 with set community 64500:200, and the same BOGONS list in a deny 10 clause.

Example output written for this lesson, not a router capture
R1#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>  0.0.0.0          192.0.2.1                0             0 64501 i
 *>  198.51.100.0     0.0.0.0                  0         32768 i
 *>  203.0.113.0      192.0.2.1                0             0 64501 i
The private prefix is gone from the table, though received-routes still lists it. That is the difference between what the neighbour sent and what your policy accepted. The first two rows are ISP A routes, and 198.51.100.0/24 is the company's own prefix.
Example output written for this lesson, not a router capture
R1#show ip bgp 10.99.0.0
% Network not in table
This is the proof that the filter, not the neighbour, removed the prefix.
Diagram
What the inbound route map does to each route
What the inbound route map does to each route

Each route is tested against clause 10 first. A match is dropped, anything else goes to clause 20 and is tagged.

  1. Route arrivesfrom ISP A
  2. Clause 10private prefix?drop it
  3. Clause 20everything else:set 64500:100
  4. Tabletagged routeis stored
Clauses run in sequence order and stop at the first match.

Step 3: refuse provider routes on the way out

Now the outbound side on R2. A community list names the tags, and the route map's first clause refuses any route that carries one of them. The second clause then lets through only the company's own prefix, so even an untagged mistake cannot leak.

ip community-list standard FROM-PROVIDERS permit 64500:100 ip community-list standard FROM-PROVIDERS permit 64500:200 ip prefix-list COMPANY-ONLY seq 5 permit 198.51.100.0/24 ! route-map TO-ISPB deny 10 match community FROM-PROVIDERS route-map TO-ISPB permit 20 match ip address prefix-list COMPANY-ONLY ! router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.5 send-community neighbor 192.0.2.5 route-map TO-ISPB out end clear ip bgp 192.0.2.5 soft out

R2. A route tagged 64500:100 or 64500:200 hits the deny clause. Only 198.51.100.0/24 passes the second clause. Use the same pattern on R1 toward ISP A.

Example output written for this lesson, not a router capture
R2#show ip bgp 0.0.0.0
BGP routing table entry for 0.0.0.0/0, version 15
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  64501
    10.255.0.1 (metric 20) from 10.255.0.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: 64500:100
This is the case the policy exists for. R2 learned the default route from R1, which learned it from ISP A. Without the outbound rule, R2 would offer it to ISP B and the company would become a path between the two providers. The entry says Not advertised to any peer, and the community line shows the tag arrived intact because R1 has send-community on the iBGP session.
Diagram
What the outbound route map does to each route
What the outbound route map does to each route

Each route is tested against clause 10 first, and a route with a provider tag is refused. Anything else goes to clause 20, which sends only the company prefix. Everything left falls to the implicit deny.

  1. Route in tableon R2
  2. Clause 10provider tag?refuse it
  3. Clause 20company prefix?send it
  4. Anything elseimplicit deny,not sent
Two ways to be refused, and only one way to be sent.

Step 4: verify what ISP B actually hears

Example output written for this lesson, not a router capture
R2#show ip bgp neighbors 192.0.2.5 advertised-routes
     Network          Next Hop            Metric LocPrf Weight Path
 *>  198.51.100.0     0.0.0.0                  0         32768 i

Total number of prefixes 1
One prefix: the company's own. The default route learned from ISP A is not here, so ISP B cannot send traffic to the company that is meant for ISP A's customers.
Example output written for this lesson, not a router capture
R2#show ip bgp community 64500:100
     Network          Next Hop            Metric LocPrf Weight Path
 *>i 0.0.0.0          10.255.0.1               0    100      0 64501 i
 * i 203.0.113.0      10.255.0.1               0    100      0 64501 i
This lists every path R2 holds with the tag, which is a quick way to confirm that the tag travelled across iBGP. 203.0.113.0/24 has no > because R2 prefers its own external path from ISP B. It is also the audit view: if a route you expected is missing here, it lost its tag on the way.
Diagram
Which check proves which step
Which check proves which step

Four verification commands, each tied to one step of the lab.

  1. received-routesWhat the provider sent,before your policy
  2. show ip bgpWhat your policy accepted
  3. show ip bgp communityWhich routes carry a tag
  4. advertised-routesWhat the other ISP hears
If a check fails, the step on the left of the row is where to look.
Diagram
Where an expected route can go missing
Where an expected route can go missing

The neighbour did not send it, the inbound policy dropped it, it lost best-path selection, or the outbound policy refused to send it on.

Route missing
  • Not sentneighbour did notoffer it
  • Inbound droproute map denyor implicit deny
  • Not bestanother pathwon selection
  • Outbound droproute map refusesto send it
Check from the neighbour side inward: received-routes, then the table, then advertised-routes.

Step 5: remove the tag and test the safety net

A policy is only trustworthy if it still protects you when something else fails. Turn off the tag on purpose: remove send-community from R1's iBGP neighbour and refresh. The default route now reaches R2 without its community, so the deny clause on R2 has nothing to match.

router bgp 64500 address-family ipv4 unicast no neighbor 10.255.0.2 send-community end clear ip bgp 10.255.0.2 soft out

R1. This removes the tag on purpose, to test the second rule. Restore it afterwards with neighbor 10.255.0.2 send-community.

Example output written for this lesson, not a router capture
R2#show ip bgp 0.0.0.0
BGP routing table entry for 0.0.0.0/0, version 18
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  64501
    10.255.0.1 (metric 20) from 10.255.0.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
The Community line is gone, so the tag was lost on the way. The route is still not advertised to any peer, because the second clause of the outbound route map permits only the company prefix and the default route does not match it.
Example output written for this lesson, not a router capture
R2#show ip bgp neighbors 192.0.2.5 advertised-routes
     Network          Next Hop            Metric LocPrf Weight Path
 *>  198.51.100.0     0.0.0.0                  0         32768 i

Total number of prefixes 1
ISP B still hears only the company prefix. The tag rule failed and the prefix rule held, which is the reason to keep both. Restore send-community on R1 and confirm the Community line returns.
Diagram
Which rule failed and which held
Which rule failed and which held

With the tag removed, the tag rule has nothing to match, so it does not refuse the default route. The prefix rule still refuses it, because the default route is not the company prefix.

Tag rule (clause 10)no tag to match,the rule does not fire
Prefix rule (clause 20)default route is notthe company prefix
One rule failed and the other held, so the leak was still stopped.

The same result can be traced for every prefix in the lab. The table below runs the four prefixes through the route maps from this lesson twice: once with the tag kept and once with it lost.

Diagram
Where each prefix ends up, tag kept and tag lost
Where each prefix ends up, tag kept and tag lost
PrefixISP B hears it: tag keptISP B hears it: tag lostWhat decides it
0.0.0.0/0No: refused by clause 10No: refused by clause 20Learned from ISP A, tagged 64500:100 by FROM-ISPA clause 20
10.99.0.0/16No: dropped at R1No: dropped at R1Matches BOGONS in FROM-ISPA clause 10, so R2 does not see it
203.0.113.0/24, iBGP copyNo: refused by clause 10No: refused by clause 20Tagged at R1 and not listed in COMPANY-ONLY
198.51.100.0/24Yes: clause 20Yes: clause 20Company prefix with no tag, listed in COMPANY-ONLY
Computed by script from the route maps and lists in this lab (BOGONS, FROM-ISPA, FROM-PROVIDERS, COMPANY-ONLY, TO-ISPB). One prefix in four reaches ISP B in both runs.

Read the two middle columns side by side. The result is the same, one prefix in four, but the clause that stops the default route changes from clause 10 to clause 20. That is the case for keeping both rules: the second one holds when the first one cannot match.

Diagram
Symptoms and the first check
Symptoms and the first check
SymptomFirst checkCommon cause
A filtered prefix still appears in the tableWas the policy refreshed with a soft clear?The route map applies to new updates only
Every route vanished after the route mapshow route-map for both clausesA missing permit clause and the implicit deny
No community on a route learned over iBGPsend-community on the sending neighbourCommunities are not sent unless configured
A provider route reaches the other ISPThe outbound route map and its directionApplied inward, or only a tag match with no prefix rule
Work from what the neighbour sent to what the other side hears, and stop at the first step that does not match.

Troubleshooting prompts

Diagram
Three symptoms and where to look first
Three symptoms and where to look first

A prefix that stays after the route map needs a soft clear and a direction check. Routes that all vanish need both clauses checked. A route with no community needs send-community on the sending neighbour.

Symptom
  • Prefix stayssoft clear, thencheck direction
  • All routes goneboth clauses,implicit deny
  • No communitysend-communityunder IPv4
Each prompt below opens with the first check shown here.
The private prefix is still in the table after the route map

The route map takes effect for new updates only. Run clear ip bgp 192.0.2.1 soft in on R1 so ISP A sends its routes again and they pass through the policy. Then check that the route map is attached in the right direction with show ip bgp neighbors 192.0.2.1 policy.

All routes disappeared after the route map was applied

A route map ends with an implicit deny. If the second clause is missing, or its sequence number was mistyped so that the clause is not there, every route that does not match clause 10 is dropped. Run show route-map FROM-ISPA and confirm both clauses are listed.

R2 shows the route from R1 with no community

R1 is not sending the tag. Check that neighbor 10.255.0.2 send-community is under the IPv4 address family on R1, then run clear ip bgp 10.255.0.2 soft out. Standard communities are not sent to a neighbour unless the neighbour has send-community.

Technical reference: RFC 1997, BGP Communities Attribute. Output above is an example written for this lesson.

Check what you learned

Predict · scenario 1

In the BOGONS prefix list every line says permit, yet the prefixes are dropped. Why?

Predict · scenario 2

R2 shows no community on the path learned from R1. What is the most likely cause?

Predict · scenario 3

send-community is removed from R1's iBGP neighbour. The default route reaches R2 with no tag. Is it advertised to ISP B?

Predict · scenario 4

A route is missing from show ip bgp but present in received-routes. Where did it go?

Predict · scenario 5

Which command shows the routes ISP A sent before your inbound policy ran?

Predict · scenario 6

send-community is removed from R1's iBGP neighbour, as in step 5. Of the four prefixes in the lab (the default route, 10.99.0.0/16, 203.0.113.0/24 and 198.51.100.0/24), how many does ISP B hear?

Predict · scenario 7

Route map FROM-ISPA contains only clause 10, a deny that matches BOGONS, and it is applied inbound for ISP A. What happens to the routes ISP A sends?

Predict · scenario 8

The company adds a second network that must be advertised to ISP B. What change does the outbound policy on R2 need?

FAQ

Why tag routes with a community instead of only filtering by prefix?
A prefix list on the outbound side has to be updated when the company adds a network. A tag says where a route came from, so one rule (do not send what came from a provider) works without a list of prefixes. Using both is safer than using either.
Why does the iBGP session need send-community?
Cisco IOS XE does not send communities to a neighbour unless told to. Without send-community on R1, the tag is removed before the route reaches R2, and the outbound rule on R2 has nothing to match.
Why use soft-reconfiguration inbound in a lab?
It keeps a copy of what the neighbour sent before the inbound policy runs, so received-routes can show the routes you filtered. It uses memory for every neighbour, so production designs use it sparingly.