Configuration Guide
OSPF Configuration Guide
35 min
introduction introduction ospf (open shortest path first) is an internal gateway protocol based on link state developed by the ietf organization, which is used to announce routing information in a single autonomous system it has the advantages of fast convergence of routing changes, no routing loops, support for variable length subnet masks (vlsm), and support for area division, etc after deploying the ospf protocol in the network, most routes will be automatically calculated and generated, eliminating the need for manual configuration by network administrators when the network topology changes, the protocol can automatically recalculate and correct routes, significantly facilitating network management before the advent of ospf, rip (routing information protocol) was widely used as an internal gateway protocol in the network since the rip is a routing protocol based on the distance vector algorithm, it suffers from issues such as slow convergence, routing loops, and poor scalability as a result, it has gradually been replaced by the ospf currently, ospf version 2 (rfc2328) is used for the ipv4 protocol, while ospf version 3 (rfc5340) is used for the ipv6 protocol basic concepts basic concepts link state link state ospf is a link state routing protocol the link can be thought of as a router's interface, and the link state can be thought of as a collection of interface and neighbor information, including the interface ip, mask, neighbors, and so on cost cost in the ospf, "cost" is used as the routing metric if the interface cost is not specified, the interface cost is calculated as the ospf reference bandwidth divided by the interface bandwidth, with the ospf reference bandwidth being 100 mbps if the calculated value is less than 1, the cost is set to 1 the calculation of the route cost is the sum of the costs of all ingress interfaces from the origin of the route to reach the local network router id router id router id is a 32 bit value used to identify an ospf device, usually in the form of ipv4 address the router id can be manually configured on the router running ospf, or automatically generated by the router typically, when a router id is not manually configured, the router will select the largest ip address among its interface addresses to be used as the router id area area ospf is a link state routing protocol in which all routers broadcast the link state of their connected networks each router then uses this comprehensive link state information to construct its own view of the network topology, upon which route calculations are based however, when the network size is large, the amount of link state broadcasts will become large, affecting the scalability of ospf to resolve this issue, ospf introduced the concept of area in ospf, there are five types of areas standard area, stub area, totally stub area, nssa (not so stubby area), and totally nssa table 1 ospf area type table 1 ospf area type true 102,504 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type classification of ospf routers classification of ospf routers when the as is split into ospf areas, the routers are further divided according to function into the following four overlapping categories internal routers a router with all directly connected networks belonging to the same area area border routers a router that attaches to multiple areas area border routers condense the topological information of their attached areas for distribution to the backbone the backbone in turn distributes the information to the other areas backbone routers a router that has an interface to the backbone area this includes all routers that interface to more than one area (i e , area border routers) however, backbone routers do not have to be area border routers routers with all interfaces connecting to the backbone area are supported as boundary routers a router that exchanges routing information with routers belonging to other autonomous systems such a router advertises as external routing information throughout the autonomous system as boundary routers may be internal or area border routers, and may or may not participate in the backbone lsa lsa lsa (link state advertisement), is used to carry and transmit link state information, including adjacent routing information, directly connected link information, area information, etc currently, various lsa types are defined the table below enumerates the commonly encountered lsa types table 2 lsa type table 2 lsa type https //docs asternos com/api/images/afdb3299 a1b3 4f29 614c fb486fc4d301 70 469 297 center figure 2 ebgp basic configuration topology 91,82 91208791208791,72 62261422787739,359 46529786003464 true left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type the support for different types of lsas in different ospf areas is as follows table 3 support for lsa dissemination in various areas table 3 support for lsa dissemination in various areas true 160,89 2,89 2,89 2,79 2,99 19999999999999 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type in totally stub and totally nssa areas, no type 3 lsas can be propagated except for the default routes of abr generated type 3 lsas ospf protocol message ospf protocol message table 4 message type table 4 message type true 148,458 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type neighbor states neighbor states in an ospf network, two routers need to establish an adjacency to exchange routing information neighbor relationships and adjacency relationships are distinct neighbor relationships ospf routers detect each other via hello packets on a shared subnet if the information (e g , area id, hello/dead intervals) carried in hello packets matches, two routers will form a neighbor relationship adjacency relationships adjacency is a deeper relationship where routers synchronize their link state databases by exchanging dd, lsr, and lsu packets there are seven types of neighbor states in ospf table 5 neighbor states table 5 neighbor states true 139,467 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type authentication authentication ospf supports three authentication methods interface authentication, area authentication, and virtual link authentication each of these methods can use either plain text authentication or message digest (md5) authentication plain text authentication transmits credentials in text, which can be intercepted by network sniffers and is therefore insecure it is not recommended in contrast, message digest (md5) authentication encrypts credentials before transmission, making it the preferred method for secure deployments table 6 authentication methods table 6 authentication methods true 213,393 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type route route aggregation aggregation route aggregation refers to the process where an area border router combines routes with common subnet prefixes into a single route and advertises it to other areas by implementing inter area route aggregation, the number of routing information is reduced, thereby reducing routing table sizes and improving device performance ospf does not support automatic route aggregation; it requires manual configuration ospf offers two aggregation mechanisms inter area route aggregation and external route aggregation inter area route aggregation, also known as abr aggregation, refers to the process where an abr combines routes generated by type 1 lsas or type 2 lsas within its directly connected area this reduces the number of type 3 lsas propagated to other directly connected areas external route aggregation, also known as asbr aggregation, refers to the process where an asbr combines external routes introduced into the ospf network this reduces the number of type 5 lsas within the ospf domain network types network types in ospf network, there are four network types based on the link layer protocol type broadcast broadcast the ospf network type defaults to broadcast when the link layer protocol is ethernet or fddi in such networks, dr and bdr are automatically elected, and manual neighbor configuration is not required non broadcast multiple access(nbma) non broadcast multiple access(nbma) the ospf network type defaults to nbma when the link layer protocol is frame relay or x 25 in such networks, dr is elected, all protocol packets are sent via unicast, and manual neighbor configuration is required point to multipoint(p2mp) point to multipoint(p2mp) ospf does not automatically assign the p2mp network type to any link layer protocol p2mp must be manually configured by overriding the original network type in this type, hello packets are sent via multicast, while other protocol packets (e g , dd, lsr, lsu) use unicast p2mp networks do not elect a dr/bdr and do not require manual neighbor configuration point to point(p2p) point to point(p2p) the ospf network type defaults to p2p when the link layer protocol is ppp, hdlc or lapb in such networks, there is no need to elect a dr/bdr multicast address 224 0 0 5 is used to send various protocol packets, allowing routers to automatically form full adjacencies without manual neighbor configuration dr in the above context means designated router and bdr means backup designated router after the election of a dr, all routers send their information only to the dr, which broadcasts the lsa this mechanism reduces synchronization overhead within the area, lowers router memory consumption, minimizes routing update traffic, and ensures all routers in the same area maintain identical link state information the dr is not manually assigned but elected autonomously by routers in the area the router with the highest priority becomes the dr (the default priority for all ospf routers is 1, but this can be modified via configuration commands; a priority of 0 excludes a router from the election) if priorities are equal, the router with the highest router id is elected as the dr ospf configuration ospf configuration prerequisite configure the interface ip so that the network layer of adjacent nodes is reachable table 7 overview of ospf configuration tasks table 7 overview of ospf configuration tasks true 87,172 23956043956042,107 23956043956042,239 52087912087916 left #4283c7 2 1 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left 1 11 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type ospf default setting ospf default setting table 8 ospf default setting table 8 ospf default setting true 159,447 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type enable ospf enable ospf table 9 enable ospf table 9 enable ospf true 161,169 5,275 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type configure ospf area configure ospf area table 10 configure ospf area table 10 configure ospf area true 158,221 97742663656885,226 02257336343115 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure cost for interface configure cost for interface table 11 configure cost for interface table 11 configure cost for interface true 163,254 5,188 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf reference bandwidth configure ospf reference bandwidth table 12 configure reference bandwidth table 12 configure reference bandwidth true 237,200 5,168 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf network type configure ospf network type table 13 configure ospf network type table 13 configure ospf network type true 168,290 3705357142857,147 62946428571428 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf interface priority configure ospf interface priority table 14 configure ospf interface priority table 14 configure ospf interface priority true 180,264 8161434977579,161 18385650224212 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf parameters configure ospf parameters table 15 configure ospf parameters table 15 configure ospf parameters true 226,247 28846153846155,132 71153846153845 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf interface authentication configure ospf interface authentication table 16 configure ospf interface authentication table 16 configure ospf interface authentication true 163,221 5,221 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf area authentication configure ospf area authentication table 17 configure ospf area authentication table 17 configure ospf area authentication true 161,224 5,220 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure ospf route introduction configure ospf route introduction table 18 configure ospf route introduction table 18 configure ospf route introduction true 255,217 5,133 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type enable ospf with bfd enable ospf with bfd table 19 enable ospf with bfd table 19 enable ospf with bfd true 158,224,224 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type display and maintenance display and maintenance table 20 ospf configuration display table 20 ospf configuration display true 117,121 64149139579351,367 35850860420646 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type typical configuration example typical configuration example networking requirements hosts on different network segments are connected via four switches, all running the ospf protocol it is required to configure ospf neighbors so that pc1 hanging under switch d and pc0 hanging under switcha can interoperate topology configuration roadmap first check that the status of each interface is up and that the wiring is correct configure the ip address of each interface and the loopback0 ip configure the ospf router id configure ospf area id, authentication methods and authentication key import direct routes into the ospf protocol on switch a and switch d procedure switch a interface loopback 0 ip address 10 0 1 226 exit ! interface ethernet 0/56 fec rs ip address 200 101 1 2/24 mtu 9216 speed 100000 ip ospf area 1 ip ospf authentication ip ospf authentication key 12345678 exit ! ospf enable ! interface ethernet 0/0 fec rs ip address 200 101 2 1/24 mtu 9216 speed 100000 description to pc0 exit ! router ospf ospf router id 10 0 1 226 redistribute connected exit switch b interface loopback 0 ip address 10 0 1 110 exit ! interface ethernet 0/48 fec rs ip address 200 101 1 1/24 mtu 9216 speed 100000 ip ospf area 1 ip ospf authentication ip ospf authentication key 12345678 exit ! interface ethernet 0/56 fec rs ip address 200 101 3 1/24 mtu 9216 speed 100000 ip ospf area 0 ip ospf message digest key 1 md5 12345678 exit ! ospf enable ! router ospf ospf router id 10 0 1 110 area 0 authentication message digest exit switch c interface loopback 0 ip address 10 0 1 225 exit ! interface ethernet 0/48 fec rs ip address 200 101 3 2/24 mtu 9216 speed 100000 ip ospf area 0 ip ospf message digest key 1 md5 12345678 exit ! interface ethernet 0/52 fec rs ip address 200 101 4 2/24 mtu 9216 speed 100000 ip ospf area 0 ip ospf message digest key 1 md5 12345678 exit ! ospf enable ! router ospf ospf router id 10 0 1 225 area 0 authentication message digest exit switch d interface loopback 0 ip address 10 0 1 221 exit ! interface ethernet 0/56 fec rs ip address 200 101 4 1/24 mtu 9216 speed 100000 ip ospf area 0 ip ospf message digest key 1 md5 12345678 exit ! interface ethernet 0/0 fec rs ip address 200 101 5 1/24 mtu 9216 speed 100000 description to pc1 exit ! ospf enable ! router ospf ospf router id 10 0 1 221 redistribute connected area 0 authentication message digest exit verify the configuration \#check if the ospf connection is established successfully switch a sonic# show ip ospf neighbor neighbor id pri state up time dead time address interface rxmtl rqstl dbsml 10 0 1 110 1 full/dr 1h44m56s 33 289s 200 101 1 1 ethernet 0/56 200 101 1 2 0 0 0 switch b sonic# show ip ospf neighbor neighbor id pri state up time dead time address interface rxmtl rqstl dbsml 10 0 1 226 1 full/backup 1h47m33s 34 972s 200 101 1 2 ethernet 0/48 200 101 1 1 0 0 0 10 0 1 225 1 full/dr 1h27m07s 32 434s 200 101 3 2 ethernet 0/56 200 101 3 1 0 0 0 switch c sonic# show ip ospf neighbor neighbor id pri state up time dead time address interface rxmtl rqstl dbsml 10 0 1 110 1 full/backup 1h28m48s 38 460s 200 101 3 1 ethernet 0/48 200 101 3 2 0 0 0 10 0 1 221 1 full/backup 1h25m24s 35 713s 200 101 4 1 ethernet 0/52 200 101 4 2 0 0 0 switch d sonic# show ip ospf neighbor neighbor id pri state up time dead time address interface rxmtl rqstl dbsml 10 0 1 225 1 full/dr 1h25m58s 37 968s 200 101 4 2 ethernet 0/56 200 101 4 1 0 0 0 \#check for successful ospf route exchange switch a sonic# show ip route ospf codes k kernel route, c connected, s static, r rip, o ospf, i is is, b bgp, e eigrp, n nhrp, t table, v vnc, v vnc direct, a babel, f pbr, f openfabric, \> selected route, \\ fib route, q queued, r rejected, b backup t trapped, o offload failure o> 10 1 0 1/32 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 10 1 0 137/32 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 10 226 148 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 10 250 0 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 99 0 0 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 172 1 1 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 o> 172 2 1 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 00 38 40 o 200 101 1 0/24 \[110/10000] is directly connected, ethernet 0/56, weight 1, 01 52 41 o> 200 101 3 0/24 \[110/10010] via 200 101 1 1, ethernet 0/56, weight 1, 01 32 06 o> 200 101 4 0/24 \[110/20010] via 200 101 1 1, ethernet 0/56, weight 1, 01 30 54 o> 200 101 5 0/24 \[110/20] via 200 101 1 1, ethernet 0/56, weight 1, 01 16 20 switch d sonic# show ip route ospf codes k kernel route, c connected, s static, r rip, o ospf, i is is, b bgp, e eigrp, n nhrp, t table, v vnc, v vnc direct, a babel, f pbr, f openfabric, \> selected route, \\ fib route, q queued, r rejected, b backup t trapped, o offload failure o> 10 250 0 0/16 \[110/20] via 200 101 4 2, ethernet 0/56, weight 1, 01 18 21 o> 172 16 1 111/32 \[110/20] via 200 101 4 2, ethernet 0/56, weight 1, 01 18 21 o> 172 16 1 226/32 \[110/20] via 200 101 4 2, ethernet 0/56, weight 1, 01 18 21 o> 200 101 1 0/24 \[110/10020] via 200 101 4 2, ethernet 0/56, weight 1, 01 29 28 o> 200 101 2 0/24 \[110/10020] via 200 101 4 2, ethernet 0/56, weight 1, 01 29 28 o> 200 101 3 0/24 \[110/10010] via 200 101 4 2, ethernet 0/56, weight 1, 01 29 28 o 200 101 4 0/24 \[110/10] is directly connected, ethernet 0/56, weight 1, 01 29 33 the subnet 200 101 2 0/24 is the directly connected segment of switch a, and the subnet 200 101 5 0/24 is the directly connected segment of switch d this indicates that both switch a and switch d get each other's directly connected routes through ospf \#verify connectivity using the ping command pc0 and pc1 can ping each other successfully
