> For the complete documentation index, see [llms.txt](https://citizenseven.gitbook.io/ccna-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://citizenseven.gitbook.io/ccna-prep/ospf-part-2.md).

# OSPF (Part 2)

Day 27

### Cost

OSPF's metric is known as **cost**. It is automatically calculated by dividing a **reference bandwidth** (default is 100 Mbps) value by the interface's bandwidth. All values less than 1 are converted to 1. To change the default reference bandwidth, enter the OSPF config mode and enter `auto-cost reference-bandwidth` followed by the value in Mbps. The reference bandwidth on all OSPF routers in the network should be the same.&#x20;

The OSPF cost to a destination is the total cost of the exit interfaces along the path. Loopback interfaces have a cost of 1. To manually configure the cost of an interface, enter the interface config mode and use the command `ip ospf cost` followed by the cost. Another way to change the cost is to change the interface bandwidth. It doesn't change the actual speed at which the interface operates. It is just used to calculate the OSPF cost. This method is not recommended. The command is `bandwidth` followed by the value in Kbps which is entered from the interface config mode.&#x20;

### Neighbours

The default hello timer is 10 seconds on an Ethernet connection. Hello messages are multicast to `224.0.0.5`. OSPF messages are encapsulated in an IP header with a value of 89 in the Protocol field. For OSPF routers to become neighbours, they have to go through several states.

#### Down

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FqLosREBvtjVZZr3H1clb%2Fimage.png?alt=media&amp;token=45199663-2e3a-4721-98b1-b5b466e71469" alt="down state" width="563"><figcaption></figcaption></figure>

* OSPF is activated on R1's `G0/0` interface
* It sends an OSPF Hello message to `224.0.0.5`
* It doesn't know about any neighbours yet

#### &#x20;Init

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FOjACmYfRGFPukUCULN6w%2Fimage.png?alt=media&amp;token=9586047b-97aa-4f3a-9c66-dce29d9e9a36" alt="init state" width="563"><figcaption></figcaption></figure>

* When R2 receives the Hello packet, it adds an entry for R1
* Hello packet is received but R2's ID is not in the Hello packet
* R1 still doesn't know about R2 yet

#### 2-way

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2F9O3L8JpJ3Tnb8TSXu04V%2Fimage.png?alt=media&amp;token=ac7338cd-a8cf-4d9e-ba92-aed0296543ae" alt="2-way state" width="563"><figcaption></figcaption></figure>

* Both routers receive Hello messages with their own RID included
* If both routers reach this state, it means they are ready to share LSAs to build a common LSDB
* **DR** (Designated Router) and **BDR** (Backup Designated Router) are elected at this point

#### Exstart

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2F3ZMI4R4wk7Nuc5tHxTN6%2Fimage.png?alt=media&amp;token=f6c92612-06d5-4c98-8c1d-597fc31341fb" alt="exstart state" width="563"><figcaption></figcaption></figure>

* Both routers prepare to exchange information about their LSDB
* The router with the higher RID becomes the **Master** and initiates the exchange. The router with  the lower RID becomes the **Slave**
* To decide between the Master and Slave, they exchange **DBD** (Database Description) packets

#### Exchange

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FRS5SuuF4uVzPBv98jycA%2Fimage.png?alt=media&amp;token=f5fa6c3e-1c87-40fe-86f3-524738774c55" alt="exchange state" width="563"><figcaption></figcaption></figure>

* The routers exchange DBDs which contain the list of LSAs in their LSDB
* These DBDs do not contain detailed information about LSAs, just basic information
* The routers compare the information they receive with their own LSDB to determine which LSA they need to request

#### Loading

<figure><img src="https://3642595937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsHxwINrQaKCeVpC90i9%2Fuploads%2FA7H3wnbD0VZ4Va10divR%2Fimage.png?alt=media&amp;token=6a0e2ae9-0a16-42e1-b3f9-eea336590e4e" alt="loading state" width="563"><figcaption></figcaption></figure>

* Routers send **LSR** (Link State Request) messages to request any LSAs they don't have
* LSAs are sent in **LSU** (Link State Update) messages
* The routers then send **LSAck** (Link State Acknowledgment) messages to acknowledge that they received the LSAs

#### Full

* The routers have a full OSPF adjacency and identical LSDBs
* They continue to send Hello packets (every 10 seconds by default) to maintain the neighbour adjacency
* Every time a Hello packet is received, a **Dead** timer (40 seconds by default) is reset
* If no Hello packet is received and Dead timer reaches 0 (zero), the neighbour is removed
* The routers keep sharing LSAs as the network changes

### OSPF Message Types

There are 5 message types in OSPF:

* 1 - Hello
* 2 - DBD
* 3 - LSR
* 4 - LSU
* 5 - LSAck

### Configuration

To activate OSPF on a particular interface, enter the interface config mode and use the command `ip ospf` followed by the process ID followed by `area` and area number.

To configure all interfaces as passive by default, enter the command `passive-interface default` from the OSPF config mode. To activate the interface, just enter `no passive-interface` followed by the interface number.&#x20;

{% file src="/files/Da5QgyQqURPcJcq6DoQU" %}

{% file src="/files/BPRShxBf1ckdekAuDD2w" %}

{% embed url="<https://youtu.be/UEyQW-EcnY8>" %}
