Hi Zero,
If lets say I add network 8.8.8.0/22 but my filter will only allow 8.8.8.0/24 to peer A. Will it work OK?
So from what you say if I have an interface on my router 8.8.8.1/24 I should announce it by adding 8.8.8.1/24 to Networks, and this is best practice?
Thanks for your tips.
Q.
No problem.
To answer your question, no - 8.8.8.0/22 is a different prefix than 8.8.8.0/24 - if you want your router to announce 8.8.8.0/24, then you need to explicitly add that prefix to your networks list. Your router can announce 8.8.8.0/22 and 8.8.8.0/24 at the same time - the Internet considers these to be completely independent announcements. Of course the /24 prefix will always win over the /22 prefix for other routers deciding how to reach, say, 8.8.8.97 because the /24 is more specific.
Think of your routing table like a pool with fish swimming around in it - and each fish represents a prefix, such as 8.8.8.0/24
Think of the BGP process like a spear-fisherman who will spear a certain kind of fish, and the networks list is the list of fish he will catch.
If your routing table has 8.8.8.0/24 as an active destination, then BGP will spear that fish and put it in the basket of prefixes being announced. If there are no 8.8.8.0/24 swimming in the waters of the IP routing table, then there will not be any 8.8.8.0/24 fish in the basket. If the route 8.8.8.0/24 is active in the routing table, then the BGP process will announce it. If it's not active in the routing table, then BGP will not announce it.
This match must be exact.
8.8.8.128/25 is a subnet of 8.8.8.0/24, but it's not an exact match - it's only "half a match" which is not a match. Since it doesn't contain 100% of the range specified, BGP will not advertise 8.8.8.0/24 based on 8.8.8.128/25
8.8.8.0/23 is a supernet of 8.8.8.0/24, but it's not an exact match - it CONTAINS a match, but it is not an actual match. Since it's not specific enough, BGP will not announce 8.8.8.0/24 based on a route to 8.8.8.0/23
If you want to originate routes for both your main /22 prefix AND for your /24 subnet of that prefix, then add
both prefixes to the networks list.
If one of your router's interfaces is configured as 8.8.8.1/24, then this will cause the route 8.8.8.0/24 to be active in the routing table as a connected route - this is a match, and thus BGP will originate the the /24 prefix. But this won't satisfy the /22 supernet. Usually, the master prefix is "nailed down" by adding a static black hole route to the master prefix.
/ip route add dst=8.8.8.0/22 type=blackhole
This is a good catch-all which discards traffic to addresses that you've not yet assigned anywhere, and it will satisfy the criteria for BGP to originate the /22 prefix into the global routing table.
The difference between ORIGINATING a route, and ANNOUNCING a route:
So using the fisherman analogy again - the networks list tells the fisherman which fish to catch, but the filter rule chains are what determines which fish the fisherman will sell to a particular customer. The fisherman may have many more fish in his basket but he will only sell the ones that match the filter rules. Stretching the analogy further - realize that when the fisherman goes to market, he may have lots of fish that he didn't catch himself. Suppose the fisherman has also bought lots of other fish from other fishermen.
These "purchased fish" are analogous to the routes your router has learned from other ISPs. You definitely do NOT want to allow routes from ISP1 to be sent to ISP2 - this will cause ISP2 to use YOU to reach the Internet for any destination that looks more appealing via your network than any other path available to ISP2. This is the most important reason you need to be very conservative with BGP filters - allow EXACTLY what you intend to advertise, and discard everything that has not matched your list.
How filters work:
Let's say you've added both the /22 and /24 prefixes to your networks list, and added the blackhole /22 route. Now your BGP process has both 8.8.8.0/24 and 8.8.8.0/22 in its collection of prefixes. When speaking to a BGP peer, Your router will use the out-filter to limit what information BGP may send to that peer.
Example 1:
1) action=accept prefix=8.8.8.0/22 prefix-length=22-24
2) action=discard
This will allow both prefixes 8.8.8.0/22 and 8.8.8.0/24 to be advertised - because the prefix 8.8.8.0/24 matches (is completely contained within) the 8.8.8.0/22 prefix, AND the rule allows matching prefixes whose length is 22-24 bits.
Example 2:
1) action=accept prefix=8.8.8.0/22
2) action=discard
This chain would ONLY allow the /22 prefix, and would drop the /24 prefix:
That's because when you don't specify a prefix length, the route must exactly match the prefix length specified.
Example 3:
Another fancy thing you could do is allow any /24 prefix which is a subset of your master /22, but not to allow the /22 prefix itself:
1) action=accept prefix=8.8.8.0/22 prefix-length=24
2) action=discard
In this example, 8.8.12.0/24 would not pass this filter because while it IS a /24 prefix, it is NOT contained in 8.8.8.0/22
I hope this information is helpful for you in understanding how BGP behaves - obviously there is a LOT more to BGP theory, behavior, and network design, but it really helps to have a firm foundational understanding of what's going on under the hood so that you can establish good best practice habits as soon as possible, which will help keep you from painting yourself into a corner that's hard to undo later on down the road.