Routage statique et dynamique
Configurer des routes statiques, OSPF et BGP sur Cisco IOS
Routes statiques
! Route statique simpleip route {{TARGET}} 255.255.255.0 {{SERVER_IP}}! Route par défautip route 0.0.0.0 0.0.0.0 {{SERVER_IP}}! Route flottante (backup — distance administrative plus haute)ip route 10.0.0.0 255.255.0.0 192.168.2.1 200 ! AD 200 > 1 (statique)! Route vers interface (PPP/serial)ip route 0.0.0.0 0.0.0.0 Serial0/0! Vérifiershow ip routeshow ip route staticshow ip route 10.0.0.0
Distances administratives par défaut
| Protocole | AD | |------------------|-----| | Connecté | 0 | | Statique | 1 | | EIGRP (interne) | 90 | | OSPF | 110 | | RIP | 120 | | EIGRP (externe) | 170 | | eBGP | 20 | | iBGP | 200 |
OSPF
! Activer OSPFconf trouter ospf 1router-id 1.1.1.1network 192.168.1.0 0.0.0.255 area 0network 10.0.0.0 0.0.0.255 area 0passive-interface GigabitEthernet0/1 ! ne pas envoyer de hello! Sur les interfacesinterface GigabitEthernet0/0ip ospf 1 area 0ip ospf cost 10ip ospf priority 100 ! DR/BDR election! OSPF authentification (MD5)interface GigabitEthernet0/0ip ospf authentication message-digestip ospf message-digest-key 1 md5 {{PASSWORD}}! Redistribuer les routes statiques dans OSPFrouter ospf 1redistribute static subnets! Vérifiershow ip ospf neighborshow ip ospf databaseshow ip ospf interface briefshow ip route ospfdebug ip ospf events
Types d'aires OSPF
| Type | Description | |----------------|------------------------------------------------------| | Backbone (0) | Aire centrale — toutes les autres s'y connectent | | Standard | Reçoit toutes les LSA (intra, inter, externe) | | Stub | Pas de routes externes (LSA type 5 bloquées) | | Totally Stub | Seulement route par défaut (LSA 3,4,5 bloquées) | | NSSA | Stub avec redistribution de routes externes locales |
BGP
! Configurer eBGPconf trouter bgp {{ASN}}bgp router-id 1.1.1.1neighbor {{SERVER_IP}} remote-as {{ASN}} ! Peer AS! Annoncer un réseaurouter bgp {{ASN}}network 203.0.113.0 mask 255.255.255.0! iBGP (même AS)router bgp {{ASN}}neighbor 10.0.0.2 remote-as {{ASN}}neighbor 10.0.0.2 update-source Loopback0neighbor 10.0.0.2 next-hop-self! Route Reflector (iBGP full mesh alternative)router bgp {{ASN}}neighbor 10.0.0.2 route-reflector-clientneighbor 10.0.0.3 route-reflector-client! Vérifiershow bgp summaryshow bgp neighbors {{SERVER_IP}}show ip bgpshow ip bgp 203.0.113.0
BGP Attributes (sélection du meilleur chemin)
Ordre de prfrence mnmonique We Love Oranges AS Oranges Mean Pure Refreshment1 Weight Cisco local plus haut prfr2 Local Preference plus haut prfr dfaut 1003 Locally Originated4 AS Path plus court prfr5 Origin IGP < EGP < Incomplete6 MED plus bas prfr7 eBGP > iBGP8 IGP metric vers next-hop9 Route la plus ancienne10 Router-ID plus bas prfr
Diagnostic réseau
! Ping étenduping 8.8.8.8 source GigabitEthernet0/0 repeat 100! Traceroutetraceroute 8.8.8.8traceroute ip 8.8.8.8 source GigabitEthernet0/0! Table de routage filtréeshow ip route | include 192.168.show ip route summary! Interface statsshow interfaces GigabitEthernet0/0show ip interface brief! ARPshow arpclear arp-cache! Debug (attention en prod)debug ip routingdebug ip ospf eventsno debug all
Linux — ip route
# Voir la table de routageip route showip route get 8888 # quel chemin pour cette destination# Ajouter une routeip route add 10000/8 via {{SERVER_IP}} dev eth0ip route add 10000/8 via {{SERVER_IP}} dev eth0 metric 100# Route par défautip route add default via {{SERVER_IP}}# Supprimerip route del 10000/8# Persistant (Debian/Ubuntu — /etc/network/interfaces ou netplan)# Netplan (/etc/netplan/01-netcfg.yaml)networkethernetseth0addresses 192168110/24gateway4 19216811routesto 10000/8via 1921681254
Pour OSPF en production : toujours configurer une router-id statique (sinon basée sur la plus haute IP d'interface, ce qui peut changer au reboot). Et activer l'authentification sur toutes les interfaces OSPF pour éviter l'injection de routes.