---
title: OSPF Configuration Guide
slug: aidc/ospf-configuration-guide
createdAt: 2025-11-28T06:36:46.931Z
---

## <font color="#1d50a2">Introduction</font>

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.

## <font color="#1d50a2">Basic Concepts</font>

### <font color="#1d50a2">Link State</font>

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.

### <font color="#1d50a2">Cost</font>

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.

### <font color="#1d50a2">Router ID</font>

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.

### <font color="#1d50a2">Area</font>

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.

<font color="#1d05a2">Table 1 OSPF area type</font>

| **Area Type**             | **Description**                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Standard Area             | Generally, the OSPF area type is defined as a standard area, which can be categorized into standard areas and backbone areas:- Standard Area: Receives routing information from within the area, between areas, and from outside the autonomous system.- Backbone Area: Serves as the central area connecting other OSPF areas, which uses the special OSPF Area 0 (often written as Area 0.0.0.0) |
| Stub Area                 | Does not accept routing information from outside the autonomous system. External route information is advertised by the area's ABR (Area Border Router) as a Type 3 default route into the area.                                                                                                                                                                                                   |
| Totally Stub Area         | Only receives internal area routing information. External routes and inter-area routing information are advertised into the area by the Area Border Router (ABR) as a Type 3 default route.                                                                                                                                                                                                        |
| NSSA (Not-So-Stubby Area) | Permits the introduction of external autonomous system routes while maintaining the characteristics of a STUB area within the autonomous system.                                                                                                                                                                                                                                                   |
| Totally NSSA              | Permits the introduction of external autonomous system routes while maintaining the characteristics of a Totally Stub area within the autonomous system.                                                                                                                                                                                                                                           |

### <font color="#1d50a2">Classification of OSPF routers</font>

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.

### <font color="#1d50a2">LSA</font>

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.

<font color="#1d05a2">Table 2 LSA Type</font>

| **LAS Type** | **Name**            | **Router**  | **Description**                                                                                                                    |
| ------------ | ------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Type-1       | Router LSA          | All routers | This LSA describes the link-state and cost of a device and can only be propagated within its originating area.                     |
| Type-2       | Network LSA         | DR          | It describes the link-state of routers in a multi-access network and is propagated only within its originating area.               |
| Type-3       | Network Summary LSA | ABR         | It describes the network prefixes and cost metrics to reach other areas, enabling routers to perform inter-area route calculation. |
| Type-4       | ASBR Summary LSA    | ABR         | It describes the route to the ASBR and is advertised to other relevant areas except the one where the ASBR resides.                |
| Type-5       | AS External LSA     | ASBR        | It describes routes to external AS and is advertised to all areas except STUB areas and NSSA.                                      |
| Type-7       | NSSA LSA            | ASBR        | It describes routes to external AS and is propagated only within NSSA.                                                             |

The support for different types of LSAs in different OSPF areas is as follows:

<font color="#1d05a2">Table 3 Support for LSA dissemination in various areas</font>

| **Area Type**     | **Type-1** | **Type-2** | **Type-3** | **Type-4** | **Type-5** |
| ----------------- | ---------- | ---------- | ---------- | ---------- | ---------- |
| Standard Area,    | 1          | 1          | 1          | 1          | 1          |
| Stub Area         | 1          | 1          | 1          | 0          | 0          |
| Totally Stub Area | 1          | 1          | 0          | 0          | 0          |
| NSSA Area         | 1          | 1          | 1          | 0          | 0          |
| Totally NSSA Area | 1          | 1          | 0          | 0          | 0          |

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.

### <font color="#1d50a2">OSPF protocol message</font>

<font color="#1d05a2">Table 4 Message type</font>

| **Message type**         | **Description**                                                                                                                                                                                                                                |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Hello                    | Hello packets are sent out each functioning router interface. They are used to discover and maintain neighbor relationships                                                                                                                    |
| DD(Database Description) | After the OSPF neighbor relationship is established, DD packets are used for describing its local LSDB (Link State Database). Upon receiving this information, routers compare it with their own LSDB to synchronize the LSDB within the area. |
| LSR（Link-State Request）  | LSR packets are used to request the necessary LSAs from the counterpart                                                                                                                                                                        |
| LSU（Link-State Update）   | LSU packets are used to response to the LSR.                                                                                                                                                                                                   |
| LSAck                    | LSAck are used to send an acknowledgment message in response to receiving an LSU from the peer.                                                                                                                                                |

### <font color="#1d50a2">Neighbor States</font>

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.

<font color="#1d05a2">Table 5 Neighbor states</font>

| **Neighbor states** | **Description**                                                                                                                                                                             |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Down                | It’s the initial stage of the neighbor session, indicating that no active neighbor has been detected.                                                                                       |
| Init                | When the received Hello packet does not contain its own Router ID, the state transitions to Init                                                                                            |
| 2-way               | When the received Hello packet contain its own Router ID, the state transitions to 2-Way. At this point, the neighbor relationship has been established and link status data can be shared. |
| Exstart             | The state transitions to Exstart when master-slave relationship negotiation begins and the DD sequence number is determined.                                                                |
| Exchange            | The state transitions to Exchange when master-slave relationship negotiation has finished and the DD message begin to be exchanged.                                                         |
| Loading             | The state transitions to Loading when DD message exchange has completed.                                                                                                                    |
| Full                | The state transitions to Full when the LSR retransmission list is empty.                                                                                                                    |

### <font color="#1d50a2">Authentication</font>

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.

<font color="#1d05a2">Table 6 Authentication methods</font>

| **Authentication**          | **Description**                                                      |
| --------------------------- | -------------------------------------------------------------------- |
| Interface Authentication    | Enable authentication for all packets on this interface.             |
| Area Authentication         | Enable authentication for all packets on all interface in this area. |
| Virtual Link Authentication | Enable authentication for all packets on virtual link.               |

### <font color="#1d50a2">Route </font>

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.

### <font color="#1d50a2">Network Types</font>

In OSPF network, there are four network types based on the link layer protocol type.

- <font color="#1d05a2">Broadcast\: </font>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.
- <font color="#1d05a2">Non-Broadcast Multiple Access(NBMA)\:</font> 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.
- <font color="#1d05a2">Point-to-Multipoint(P2MP)\: </font>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.
- <font color="#1d05a2">Point-to-Point(P2P)\: </font>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.

## <font color="#1d50a2">OSPF Configuration</font>

**Prerequisite**: Configure the interface IP so that the network layer of adjacent nodes is reachable.

<font color="#1d05a2">Table 7 Overview of OSPF Configuration Tasks</font>

| **Configuration Tasks**                 | **Description** | **Refer to**                                                                                                                                   |                                                                                        |
| --------------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| Basic functions                         | Enable OSPF     | Required                                                                                                                                       | [Enable OSPF](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#enable-ospf)  |
| Configure OSPF area                     | Required        | [Configure OSPF area](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-area)                                          |                                                                                        |
| Configure cost for interface            | Optional        | [Configure cost for interface](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-cost-for-interface)                        |                                                                                        |
| Configure OSPF reference bandwidth      | Optional        | [Configure OSPF reference bandwidth](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-reference-bandwidth)            |                                                                                        |
| Configure OSPF network type             | Optional        | [Configure OSPF network type](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-network-type)                          |                                                                                        |
| Configure OSPF interface priority       | Optional        | [Configure OSPF interface priority](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-interface-priority)              |                                                                                        |
| Configure OSPF parameters               | Optional        | [Configure OSPF parameters](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-parameters)                              |                                                                                        |
| Configure OSPF interface authentication | Optional        | [Configure OSPF interface authentication](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-interface-authentication)  |                                                                                        |
| Configure OSPF area authentication      | Optional        | [Configure OSPF area authentication](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-area-authentication)            |                                                                                        |
| Configure OSPF route introduction       | Optional        | [Configure OSPF route introduction](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#configure-ospf-route-introduction)              |                                                                                        |
| Enable BFD with OSPF Linkage            | Optional        | [Enable OSPF with BFD](https://v1.docs.asternos.com/aidc/ospf-configuration-guide#enable-ospf-with-bfd)                                        |                                                                                        |

### <font color="#1d50a2">OSPF Default Setting</font>

<font color="#1d05a2">Table 8 OSPF Default Setting</font>

| **Parameter**   | **Default value**                                                               |
| --------------- | ------------------------------------------------------------------------------- |
| OSPF            | Disable                                                                         |
| Area type       | Standard Area                                                                   |
| Router ID       | Largest address in interface IP address list                                    |
| Network type    | Broadcast                                                                       |
| OSPF parameters | Hello packets interval: 10sLSA retransmission interval: 5sTimeout interval: 40s |

### <font color="#1d50a2">Enable OSPF</font>

<font color="#1d05a2">Table 9 Enable OSPF</font>

| **Purpose**                       | **Commands**                          | **Description**                                                        |
| --------------------------------- | ------------------------------------- | ---------------------------------------------------------------------- |
| Enter global configuration view.  | **configure terminal**                | -                                                                      |
| Configure OSPF packet trap to CPU | **ospf enable**                       | Default disable                                                        |
| Configure OSPF instance.          | **router ospf** \[**vrf** *vrf-name*] | -                                                                      |
| Configure the Router ID           | **ospf router-id** *x.x.x.x*          | The Router ID uniquely identifies a device within an Autonomous System |

### <font color="#1d50a2">Configure OSPF area</font>

<font color="#1d05a2">Table 10 Configure OSPF Area</font>

| **Purpose**                        | **Commands**                                                                                                                                         | **Description**                                                                                                                                                         |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter global configuration view.   | **configure terminal**                                                                                                                               | -                                                                                                                                                                       |
| Enter interface configuration view | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                                                                                                                                                                       |
| Configure area-id                  | **ip ospf area** *area\_id*                                                                                                                          | *area\_id*: range 0-4294967295.                                                                                                                                         |
| Enter OSPF configuration view.     | **router ospf** \[**vrf** *vrf\_name*]                                                                                                               | -                                                                                                                                                                       |
| (Optional)Configure area type      | **area** *area\_id* \{**stub\|nssa**}                                                                                                                | Area type cannot be configured as a Stub area or NSSA area when area id is 0. By default, an area without explicit type configuration is classified as a standard area. |

### <font color="#1d50a2">Configure cost for interface</font>

<font color="#1d05a2">Table 11 Configure Cost For Interface</font>

| **Purpose**                        | **Commands**                                                                                                                                         | **Description**         |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| Enter global configuration view    | **configure terminal**                                                                                                                               | -                       |
| Enter interface configuration view | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                       |
| Configure the cost                 | **ip ospf cost** *value*                                                                                                                             | *value*: range 1-65535. |

### <font color="#1d50a2">Configure OSPF reference bandwidth</font>

<font color="#1d05a2">Table 12 Configure Reference Bandwidth</font>

| **Purpose**                     | **Commands**                                  | **Description**                    |
| ------------------------------- | --------------------------------------------- | ---------------------------------- |
| Enter global configuration view | **configure terminal**                        | -                                  |
| Enter OSPF configuration view.  | **router ospf** \[**vrf** *vrf\_name*]        | -                                  |
| Configure reference bandwidth   | **auto-cost reference-bandwidth** *bandwidth* | *bandwidth:* range 1- 4294967Mbps. |

### <font color="#1d50a2">Configure OSPF network type</font>

<font color="#1d05a2">Table 13 Configure OSPF Network Type</font>

| **Purpose**                        | **Commands**                                                                                                                                         | **Description**                        |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| Enter global configuration view    | **configure terminal**                                                                                                                               | -                                      |
| Enter interface configuration view | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                                      |
| Configure OSPF network type        | **ip ospf network** \{**broadcast**\|**non-broadcast**\|**point-to-multipoint**\|**point-to-point**}                                                 | The default network type is broadcast. |

### <font color="#1d50a2">Configure OSPF interface priority</font>

<font color="#1d05a2">Table 14 Configure OSPF Interface Priority</font>

| **Purpose**                        | **Commands**                                                                                                                                         | **Description**          |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| Enter global configuration view    | **configure terminal**                                                                                                                               | -                        |
| Enter interface configuration view | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                        |
| Configure OSPF priority            | **ip ospf priority** *priority*                                                                                                                      | *priority*: range 0-255. |

### <font color="#1d50a2">Configure OSPF parameters</font>

<font color="#1d05a2">Table 15 Configure OSPF Parameters</font>

| **Purpose**                           | **Commands**                                                                                                                                         | **Description** |
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| Enter global configuration view       | **configure terminal**                                                                                                                               | -               |
| Enter interface configuration view    | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -               |
| Configure Hello packets interval      | **ip ospf hello-interval** *seconds*                                                                                                                 | range: 1-65535  |
| Configure timeout interval            | **ip ospf dead-interval** *seconds*                                                                                                                  | range: 1-65535  |
| Configure LSA retransmission interval | **ip ospf retransmit-interval** *seconds*                                                                                                            | range: 1-65535  |

### <font color="#1d50a2">Configure OSPF interface authentication</font>

<font color="#1d05a2">Table 16 Configure OSPF Interface Authentication</font>

| **Purpose**                                                   | **Commands**                                                                                                                                         | **Description**                                                                                                                                                                                                               |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter global configuration view                               | **configure terminal**                                                                                                                               | -                                                                                                                                                                                                                             |
| Enter interface configuration view                            | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                                                                                                                                                                                                                             |
| Configure Authentication Methods                              | **ip ospf authentication** \[**message-digest**]                                                                                                     | When the configuration command does not include 'message-digest', the authentication method is plain text authentication; when 'message-digest' is included, the authentication method is message digest (md5) authentication |
| Configure the key for plain text authentication               | **ip ospf authentication-key** *auth-key*                                                                                                            | *auth-key*: length should be no more than 8 characters.                                                                                                                                                                       |
| Configure the key for method is message digest authentication | **ip ospf message-digest-key** *key-id* **md5** *auth-key*                                                                                           | *key-id*: range 1-255. *auth-key*: length should be no more than 16 characters.                                                                                                                                               |

### <font color="#1d50a2">Configure OSPF area authentication</font>

<font color="#1d05a2">Table 17 Configure OSPF Area Authentication</font>

| **Purpose**                                                   | **Commands**                                                                                                                                         | **Description**                                                                                                                                                                                                               |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter global configuration view                               | **configure terminal**                                                                                                                               | -                                                                                                                                                                                                                             |
| Enter interface configuration view                            | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                                                                                                                                                                                                                             |
| Configure the key for plain text authentication               | **ip ospf authentication-key** *auth-key*                                                                                                            | *auth-key*: length should be no more than 8 characters.                                                                                                                                                                       |
| Configure the key for method is message digest authentication | **ip ospf message-digest-key** *key-id* **md5** *auth-key*                                                                                           | *key-id*: range 1-255. *auth-key*: length should be no more than 16 characters.                                                                                                                                               |
| Exit interface configuration view                             | **exit**                                                                                                                                             | -                                                                                                                                                                                                                             |
| Enter OSPF configuration view.                                | **router ospf** \[**vrf** *vrf\_name*]                                                                                                               | -                                                                                                                                                                                                                             |
| Configure Authentication Methods                              | **area *area-id* authentication** \[**message-digest**]                                                                                              | When the configuration command does not include 'message-digest', the authentication method is plain text authentication; when 'message-digest' is included, the authentication method is message digest (md5) authentication |

### <font color="#1d50a2">Configure OSPF route introduction</font>

<font color="#1d05a2">Table 18 Configure OSPF Route Introduction</font>

| **Purpose**                     | **Commands**                                                                           | **Description** |
| ------------------------------- | -------------------------------------------------------------------------------------- | --------------- |
| Enter global configuration view | **configure terminal**                                                                 | -               |
| Enter OSPF config view.         | **router ospf** \[**vrf** *vrf\_name*]                                                 | -               |
| Configure route introduction    | **redistribute** \{**ospf**\|**kernel**\| **connected**\|**static**\|**rip**\|**bgp**} | -               |

### <font color="#1d50a2">Enable OSPF with BFD</font>

<font color="#1d05a2">Table 19 Enable OSPF with BFD</font>

| **Purpose**                        | **Commands**                                                                                                                                         | **Description**                                                                                                                 |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Enter global configuration view    | **configure terminal**                                                                                                                               | -                                                                                                                               |
| Enter interface configuration view | **interface** \{**ethernet** *interface-name*\[.*subinterface-number*] \|**link-aggregation** *lag-id*\[.*subinterface-number*]\|**vlan** *vlan-id*} | -                                                                                                                               |
| Configure OSPF with BFD.           | **ip ospf bfd** \[**profile** *profile-name*]                                                                                                        | You can modify BFD session parameters via binding to a user-defined BFD profile. The default BFD parameters are set to 3×300ms. |

### <font color="#1d50a2">Display and Maintenance</font>

<font color="#1d05a2">Table 20 OSPF Configuration Display</font>

| **Purpose**                                                   | **Commands**                          | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Show OSPF neighbor information                                | **show ip ospf neighbor** \[OPTIONs]  | The options for OPTIONs are as follows:**all**: Display summary information of all neighbors.**json**: Display OSPF neighbor information in json format.**detail**: Display neighbor details.**A.B.C.D**: Display information about neighbors with the specified Router ID.**ethernet**: Display neighbor information for the specified physical port.**vlan**: Display neighbor information for the specified VLANIF.**link-aggregation**: Display neighbor information for the specified LAG port. |
| Display OSPF neighbor information for the specified interface | **show ip ospf interface** \[OPTIONs] | The options for OPTIONs are as follows:**ethernet**: Display neighbor information for the specified physical port.**vlan**: Display neighbor information for the specified VLANIF.**link-aggregation**: Display neighbor information for the specified LAG port.**json**: Display OSPF neighbor information in json format.**traffic**: Display OSPF packet counts.                                                                                                                                  |
| Display OSPF Routing Information                              | **show ip ospf route** \[OPTIONs]     | The options for OPTIONs are as follows:**json**: Display OSPF routing information in json format.                                                                                                                                                                                                                                                                                                                                                                                                    |
| Display OSPF Link-State Information                           | **show ip ospf database**             | -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

### <font color="#1d50a2">Typical Configuration Example</font>

1. 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.
2. Topology

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/CXdNp89G9FRuUIS3kXxGa-20251127-072359.png" size="80" width="548" height="326" position="center" caption="Figure 3 OSPF basic configuration topology" darkWidth="548" darkHeight="326" showCaption="true"}

3. Configuration Roadmap
4. First check that the status of each interface is UP and that the wiring is correct.
5. Configure the IP address of each interface and the Loopback0 IP.
6. Configure the OSPF Router-ID.
7. Configure OSPF Area ID, authentication methods and authentication-key.
8. Import direct routes into the OSPF protocol on Switch A and Switch D.
9. Procedure

**Switch A**

```plaintext
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**

```plaintext
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**

```plaintext
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
```

4. Verify the configuration

\#Check if the OSPF connection is established successfully.

**Switch A**

```plaintext
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**

```plaintext
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**

```plaintext
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**

```plaintext
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**

```plaintext
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**

```plaintext
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.

