Assume a simplified case in which router R1 is connected to two BGP peers: one eBGP peer and one iBGP peer. Is there a possibility to advertise directly connected routes only to one of them automatically i.e. whenever a new directly connected network to R1 appears it is advertised only to one of BGP peers while the other peer receives other routes but not those that are directly connected to R1?
Yes, absolutely; there are a variety of ways to accomplish this. I'll suggest two just to give you some inspiration.
Match Protocol option
On your route-map toward the BGP neighbors, you can
match protocol connected in a stanza to determine whether you propagate those routes. For example:
route-map to-isp deny 100 description don't announce my connected routes to the ISP match protocol connected
When redistributing connected into BGP, add a community to the routes so you can match on it.
ip community-list standard internal-routes permit 65000:10 route-map connected-to-bgp permit 100 set community 65000:10 route-map to-isp deny 100 match community internal-routes
It will be dependent on the exact operating system that runs on the router, but generally redistribution is configured on the router level. I.E. apply to all peers.
You can however filters routes that are announced to peers based on various criteria, and especially communities.
So one way of doing this is:
- apply a route-map on the "redistribute connected" statement. This route map set a community. So all routes that are redistributed now have this label on them.
- apply a route-map to the routes announced to peer A to allow this community.
- apply a route-map to the routes announced to peer B to deny this community.