MDstable
NoteSnippetChecklistPlaybook

BGP — eBGP & iBGP Configuration

Configurer BGP (eBGP et iBGP), filtrage de routes, communities et attributs

snippetadvanced 2025-05-14 7 min read
bgpebgpibgproutingciscoas-pathcommunityprefix-listroute-map

Concepts fondamentaux

BGP Border Gateway Protocol protocole EGP entre AS path-vector
Utilisation routage Internet inter-AS, MPLS/VPN datacenters
eBGP External BGP entre AS diffrents TTL 1 par dfaut
iBGP Internal BGP au sein du mme AS TTL 255
iBGP full-mesh requis ou utiliser Route Reflector Confederation
Attributs BGP ordre de dcision du plus au moins prioritaire
1 Weight Cisco uniquement local
2 LOCAL_PREF iBGP plus lev prfr
3 Locally originated network statement ou redistribute
4 AS_PATH plus court prfr
5 ORIGIN IGP < EGP < incomplete
6 MED plus bas prfr entre voisins du mme AS upstream
7 eBGP > iBGP
8 IGP metric vers next-hop
9 Router-ID plus bas prfr
BGP States Idle Connect Active OpenSent OpenConfirm Established

eBGP — Configuration de base

Session eBGP simple

text
Variables
{{LOCAL_AS}}
{{BGP_ROUTER_ID}}
{{ISP_IP}}
{{ISP_AS}}
{{BGP_MD5_KEY}}
{{OWN_PREFIX}}
{{OWN_MASK}}
{{OWN_PREFIX2}}
{{OWN_MASK2}}
conf t
router bgp {{LOCAL_AS}}
bgp router-id {{BGP_ROUTER_ID}} ! ex: loopback0 address
bgp log-neighbor-changes ! syslog sur les changements d'état
! Voisin eBGP (ISP)
neighbor {{ISP_IP}} remote-as {{ISP_AS}}
neighbor {{ISP_IP}} description ** ISP Upstream **
neighbor {{ISP_IP}} password {{BGP_MD5_KEY}} ! MD5 authentication
neighbor {{ISP_IP}} update-source Loopback0 ! si multihop
! Annoncer nos propres préfixes (route doit exister dans la table de routage)
network {{OWN_PREFIX}} mask {{OWN_MASK}}
network {{OWN_PREFIX2}} mask {{OWN_MASK2}}

eBGP Multihop (voisin pas directement connecté)

text
Variables
{{LOCAL_AS}}
{{REMOTE_IP}}
{{REMOTE_AS}}
conf t
router bgp {{LOCAL_AS}}
neighbor {{REMOTE_IP}} remote-as {{REMOTE_AS}}
neighbor {{REMOTE_IP}} ebgp-multihop 2 ! TTL = 2 (1 saut intermédiaire)
neighbor {{REMOTE_IP}} update-source Loopback0

Dual-homed (deux ISPs)

text
Variables
{{LOCAL_AS}}
{{ISP1_IP}}
{{ISP1_AS}}
{{ISP2_IP}}
{{ISP2_AS}}
conf t
router bgp {{LOCAL_AS}}
! ISP1
neighbor {{ISP1_IP}} remote-as {{ISP1_AS}}
neighbor {{ISP1_IP}} description ** ISP1 Primary **
! ISP2
neighbor {{ISP2_IP}} remote-as {{ISP2_AS}}
neighbor {{ISP2_IP}} description ** ISP2 Backup **
! Route par défaut reçue des deux ISPs
! Utiliser LOCAL_PREF pour préférer ISP1
neighbor {{ISP1_IP}} route-map SET_LOCALPREF_HIGH in
neighbor {{ISP2_IP}} route-map SET_LOCALPREF_LOW in
! Route-maps
route-map SET_LOCALPREF_HIGH permit 10
set local-preference 200
route-map SET_LOCALPREF_LOW permit 10
set local-preference 100

iBGP — Configuration

Full-mesh (petits AS)

text
Variables
{{AS}}
{{ROUTER_ID}}
{{IBGP_PEER1}}
{{IBGP_PEER2}}
! Sur chaque routeur iBGP — déclarer TOUS les autres routeurs iBGP
conf t
router bgp {{AS}}
bgp router-id {{ROUTER_ID}}
! Toujours utiliser les loopbacks pour les sessions iBGP (stabilité)
neighbor {{IBGP_PEER1}} remote-as {{AS}}
neighbor {{IBGP_PEER1}} update-source Loopback0
neighbor {{IBGP_PEER1}} next-hop-self ! iBGP: forcer next-hop = soi-même
neighbor {{IBGP_PEER2}} remote-as {{AS}}
neighbor {{IBGP_PEER2}} update-source Loopback0
neighbor {{IBGP_PEER2}} next-hop-self

Route Reflector

text
Variables
{{AS}}
{{RR_ROUTER_ID}}
{{CLUSTER_ID}}
{{CLIENT1_IP}}
{{CLIENT2_IP}}
{{RR2_IP}}
{{RR_IP}}
! ── Route Reflector (RR) ──────────────────────────────
conf t
router bgp {{AS}}
bgp router-id {{RR_ROUTER_ID}}
bgp cluster-id {{CLUSTER_ID}} ! si plusieurs RRs dans le cluster
! Clients du RR
neighbor {{CLIENT1_IP}} remote-as {{AS}}
neighbor {{CLIENT1_IP}} update-source Loopback0
neighbor {{CLIENT1_IP}} route-reflector-client
neighbor {{CLIENT2_IP}} remote-as {{AS}}
neighbor {{CLIENT2_IP}} update-source Loopback0
neighbor {{CLIENT2_IP}} route-reflector-client
! Peerings entre RRs (non-clients — full-mesh entre RRs)
neighbor {{RR2_IP}} remote-as {{AS}}
neighbor {{RR2_IP}} update-source Loopback0
! ── Client RR ──────────────────────────────────────────
conf t
router bgp {{AS}}
neighbor {{RR_IP}} remote-as {{AS}}
neighbor {{RR_IP}} update-source Loopback0
! Pas de route-reflector-client côté client

Filtrage — Prefix-list

text
Variables
{{OWN_PREFIX1}}
{{PREFIX1_LEN}}
{{OWN_PREFIX2}}
{{PREFIX2_LEN}}
{{AS}}
{{ISP_IP}}
conf t
! Autoriser uniquement nos propres préfixes en sortie vers l'ISP
ip prefix-list OWN_PREFIXES seq 5 permit {{OWN_PREFIX1}}/{{PREFIX1_LEN}}
ip prefix-list OWN_PREFIXES seq 10 permit {{OWN_PREFIX2}}/{{PREFIX2_LEN}}
ip prefix-list OWN_PREFIXES seq 99 deny 0.0.0.0/0 le 32 ! deny tout le reste
! Bloquer les préfixes spécifiques reçus d'un voisin
ip prefix-list DENY_BOGONS seq 5 deny 10.0.0.0/8 le 32
ip prefix-list DENY_BOGONS seq 10 deny 172.16.0.0/12 le 32
ip prefix-list DENY_BOGONS seq 15 deny 192.168.0.0/16 le 32
ip prefix-list DENY_BOGONS seq 20 deny 0.0.0.0/8 le 32
ip prefix-list DENY_BOGONS seq 99 permit 0.0.0.0/0 le 32
! Appliquer sur le voisin
router bgp {{AS}}
neighbor {{ISP_IP}} prefix-list OWN_PREFIXES out
neighbor {{ISP_IP}} prefix-list DENY_BOGONS in

Filtrage — Route-map

text
Variables
{{AS}}
{{ISP1_IP}}
{{ISP2_IP}}
conf t
! Route-map pour manipuler LOCAL_PREF en entrée
route-map ISP1_IN permit 10
match ip address prefix-list ALLOWED_IN
set local-preference 200
set community 65000:100 additive
route-map ISP1_IN permit 99
! permit implicite pour tout le reste (sans set = pas de modification)
! Route-map pour manipulation AS-PATH en sortie (prepending)
route-map PREPEND_OUT permit 10
match ip address prefix-list OWN_PREFIXES
set as-path prepend {{AS}} {{AS}} {{AS}} ! triple prepend = moins préféré
route-map PREPEND_OUT permit 99
! Appliquer
router bgp {{AS}}
neighbor {{ISP1_IP}} route-map ISP1_IN in
neighbor {{ISP2_IP}} route-map PREPEND_OUT out

BGP Communities

text
conf t
! Activer le format XX:YY pour les communities (recommandé)
ip bgp-community new-format
! Route-map pour setter une community
route-map SET_COMMUNITY permit 10
set community 65000:200 additive ! ajouter sans remplacer
! set community no-export ! ne pas exporter vers eBGP peers
! set community no-advertise ! ne pas annoncer à aucun voisin
! Match sur une community
ip community-list standard COMM_200 permit 65000:200
route-map MATCH_COMMUNITY permit 10
match community COMM_200
set local-preference 150

Attributs — Weight (Cisco only)

text
Variables
{{AS}}
{{ISP1_IP}}
{{PREFIX_LIST}}
conf t
! Weight : local au routeur, non propagé — priorité maximale dans la décision
router bgp {{AS}}
! Via neighbor (toutes les routes de ce voisin)
neighbor {{ISP1_IP}} weight 200
! Via route-map (granularité par préfixe)
neighbor {{ISP1_IP}} route-map SET_WEIGHT in
route-map SET_WEIGHT permit 10
match ip address prefix-list {{PREFIX_LIST}}
set weight 300
route-map SET_WEIGHT permit 99
set weight 100

Maintenance et soft-reconfiguration

text
Variables
{{AS}}
{{PEER_IP}}
conf t
router bgp {{AS}}
! Activer la soft-reconfiguration (stocke les routes reçues avant filtre)
neighbor {{PEER_IP}} soft-reconfiguration inbound
! Réappliquer les policies sans reset de session (soft reset)
clear ip bgp {{PEER_IP}} soft
clear ip bgp {{PEER_IP}} soft in ! réappliquer filtres inbound
clear ip bgp {{PEER_IP}} soft out ! réannoncer routes outbound
! Reset hard de session (interruption traffic !)
clear ip bgp {{PEER_IP}}
! Reset toutes les sessions BGP
clear ip bgp *

Vérifications

text
Variables
{{PREFIX}}
{{LEN}}
{{PEER_IP}}
! Vue globale des sessions
show ip bgp summary
! Exemple de sortie :
! Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
! 203.0.113.1 4 65001 1234 5678 100 0 0 2d05h 150000
! Détail d'un préfixe
show ip bgp {{PREFIX}}/{{LEN}}
show ip bgp {{PREFIX}}
! Routes reçues d'un voisin (nécessite soft-reconfiguration inbound)
show ip bgp neighbors {{PEER_IP}} received-routes
show ip bgp neighbors {{PEER_IP}} advertised-routes
! Détail d'un voisin (timers, capabilities, stats)
show ip bgp neighbors {{PEER_IP}}
! Routes BGP dans la table de routage
show ip route bgp
! Filtre sur l'AS-PATH
show ip bgp regexp _65001_
! Contenu de la BGP table
show ip bgp
show ip bgp | begin Network ! ignorer l'en-tête

Troubleshooting — Session qui ne monte pas

text
Variables
{{PEER_IP}}
! Causes fréquentes :
! 1. AS number incorrect → show ip bgp neighbors | include remote AS
! 2. TTL eBGP (voisin pas directement connecté) → ebgp-multihop
! 3. ACL bloquant port 179 → show ip access-lists
! 4. Routage manquant vers le voisin → ping {{PEER_IP}}
! 5. Authentification MD5 → show ip bgp neighbors | include password
! 6. update-source incorrect → show ip bgp neighbors | include source
! 7. Mauvaise IP dans neighbor statement
! Debug BGP (très verbeux — utiliser avec précaution)
debug ip bgp {{PEER_IP}} events
debug ip bgp {{PEER_IP}} updates
undebug all
💡 Tip —

En eBGP, le TTL est 1 par défaut — cela signifie que les deux routeurs doivent être directement connectés (ou partager un subnet). Si le voisin eBGP est accessible via plusieurs sauts (par exemple, via un réseau de transit ou une loopback), utiliser neighbor {{PEER_IP}} ebgp-multihop 2 (ou plus). Côté sécurité, activer GTSM (neighbor X ttl-security hops 1) sur les sessions eBGP directes pour rejeter les paquets BGP avec TTL < 254.

OPS·BRAIN v1.027 notes · Networklocal