# OSPF 2 - Cost, Neighbours and Configs

## OSPF Cost

**OSPF's METRIC is COST !!**

* It is automatically calculated based on the BANDWIDTH (speed) of the interface
* It is calculated by dividing a **reference bandwidth** value by the **interface's bandwidth**
  * The **defaul**t reference bandwidth is **100Mbps,** so lets say an interface is 10Mbps
    * Reference: 100Mbps / Interface:10Mbps: **COST= 10**
    * Reference: 100Mbps / Interface:100Mbps:     **COST = 1**
    * Reference: 100Mbps / Interface:1000Mbps:   **COST = 1**
    * Reference: 100Mbps / Interface:10000Mbps: **COST = 1**
* **All values less than 1, will be converted to 1**
* **Therefore Fast Ethernet, Gigabit Ethernet, 10/100Gig Ethernet are ALL equal with a value of 1**
* `R3# show ip ospf interface fa2/0`\
  &#x20;    `Shown in 2 places : Cost 1`
* BUT!!!! we CAN change this with the following command\
  `R1(config-router)# auto-cost reference-bandwidth <reference bandwidth in megabits-per-second>`\
  `R1(config-router)# auto-cost reference-bandwidth 100000`
* You should configure a reference bandwidth GREATER than the fastest links in your network (to allow for future upgrades) across ALL routers in the network

![](/files/-MIGVNur3eqpW-MxjOoP)

### Cost

The OSPF cost to a destination is the TOTAL cost of the '**outgoing/exit**' interfaces. Just like spanning tree cost<br>

![](/files/-MIIi-wZIyMxtFY4zez-)

For example: R1's cost to reach the 192.168.4.0/24 network is:

* Exit of R1's Gi0/0, exit of R2's G1/0 and the exit of R4's Gi1/0 (taking the reference bandwidth of 100000) is 100+100+100=300
* Now loopback interfaces have a cost of 1 - what is the cost of reaching R2's loopback interface of 2.2.2.2?
  * R1's exit interface = 100 and R2's loopback interface = 1
  * So to reach R2's loopback interface is 100+1=101

![](/files/-MIImWNb3vhc31sd0998)

![](/files/-MIInS8ffZxvuMcFwTfM)

### Manually Configure the OSPF Cost of an Interface

`R1(config)# interface gi0/0` \
`R1(config-if)# ip ospf cost ?`  \
&#x20;       `<1 - 65535>   Cost`\
\
`R1(config-if)#interface gi0/0 cost 10000`

* This cost is configured directly on the interface and will take priority over the 'auto-calculated cost'
* We have configured the interface as 10000 and we can now see the cost as 10000 and not as 100 (we are still using the reference bandwidth as 100000)

![](/files/-MIIr80qtSVFMqc79Wes)

* One more option to change the OSPF cost of an interface is to change the 'bandwidth' of the interface.\
  \&#xNAN;**`R1(config-if)# bandwidth ?`**\
  &#x20;**`<1 - 10000000>      Bandwidth in kilobits`**\
  &#x20;**Remember** - changing the bandwidth does **NOT** change the **SPEED** of the interface - the bandwidth command is for COST calculation from the  OSPF cost formula:\
  &#x20;       OSPF COST = reference bandwidth \ interface bandwidth

{% hint style="danger" %}
This method is not recommended as the 'bandwidth' VALUE is used in other calculations so don't want to go and change this.\
Rather use the **`auto-cost reference bandwidth`**&#x61;nd THEN use  the **`ip ospf cost`** to change the individual interfaces if you want.
{% endhint %}

#### Lets Summarise

* There are 3 ways to modify the OSPF cost:
  * Change the **reference bandwidth**`R1(config-router)# auto-cost reference-bandwidth <in megabits per second>`
  * Manual Configuration\
    `R1(config-if)# ip ospf cost <cost>`
  * Change the **interface bandwidth**\
    `R1(config-if)# bandwidth <kilobits per second>`
* To check the cost of the interfaces we can use:
  * **`R3# show ip ospf interface brief`**

![](/files/-MIIvs3kcI2pODE7SSC6)

## OSPF Neighbours

Ensuring routers successfully become OSPF neighbours is the main task in configuring and troubleshooting OSPF.

* Once they become neighbours, they automatically do the work of sharing network information, calculating routes etc. **MAKE SURE OSPF IS ACTIVATED ON THE CORRECT INTERFACES** and the correct conditions are met to allow the routers to become neighbours, otherwise OSPF wont work !!
* So how do OSPF routers become neighbours?
  * When OSPF is activated on an INTERFACE, the router starts sending **hello** messages out of that interface at regular intervals (default every 10 seconds for Ethernet - they are different for other types of media ) - that's why we issue the command `R1(config-router)# passive-interface gi2/0` to **STOP hello** messages being sent to non OSPF aware devices.
* By exchanging "hello" messages with other OSPF aware routers, they check that they are compatible in becoming OSPF neighbours.
* These messages are multicast to the OSPF IP address 224.0.0.5 (remember RIP=224.0.0.9, EIGRP=224.0.0.10) and are ENCAPSULATED into an **IP header of 89** to indicate "OSPF" (remember TCP=6) \[If you look into an OSPF hello packet you will see in the "protocol" field 0x59 - this is hexadecimal and converting this to decimal you will get "89"

![](/files/-MIQjcDZ-ZUJk0YBGC5V)

## OSPF States

For OSPF to become neighbours, they have to go through various states.

![](/files/-MIJkHRnnfGpuxkycyC_)

Lets assume OSPF has already been activated on R2's Gi0/0 interface, then OSPF is activated on R1's Gi0/0 interface

* R1 send OSPF **hello** messages to 224.0.0.5 with R1's router ID (1.1.1.1) and neighbour RID (0.0.0.0) - it doesn't know its neighbour RID ....so this OSPF state is known as the\
  \&#xNAN;**"DOWN STATE"**
* When **R2** receives the hello packet, it will add an entry for R1 into its OSPF NEIGHBOUR table and its now in the\
  \&#xNAN;**"INIT STATE"**
* R2 will send a hello packet containing the RID of BOTH routers. R1 will insert R2 into its OSPF NEIGHBOUR table and then R1 will send ANOTHER hello packet, this time containing R2's RID of 2.2.2.2. Now both routers are in the\
  \&#xNAN;**"2-WAY STATE"**\
  The 2-way state means that the router has received a hello packet with its OWN router ID in it. Also at this point a Designated Router (DR) and Backup Designated router (BDR) will be elected.
* Once the routers reach the 2-way state, the conditions have been met for them to become OSPF neighbours and are now ready to share LSA's to build a common LSDB of the network. To do this one of them will have to start the exchange and the one with the highest RID will become the **MASTER** Router and the other will become the **SLAVE** Router, This is done via the exchange of Data Base Description (DBD) packets, and this is known as the \
  "**EXSTART STATE"**
* These DBD packets contain a list of the LSA's currently in their LSDB and the routers will then determine which LSA's they must receive from their neighbour. This is known as the \
  \&#xNAN;**"EXCHANGE STATE"**
* The routers now know which LSA's they should receive from their neighbours from the DBD packets received earlier. The router now send out LSR's (Link State Request) to their neighbour requesting any LSA's they don't have. These LSA's are sent in LSU's (Links State Updates) and the neighbour router responds with LSAck message to acknowledge they received the LSA's. Now the routers have the same LSDB. This is called the\
  \&#xNAN;**"LOADING STATE"**
* The final state is where the routers have a full adjacency and identical LSDB's. They continue to send hello messages every 10 seconds (by default) to maintain the neighbour adjacency. Every time a hello packet is received on a router the "DEAD TIMER" is reset (every 40 seconds). This should count down to 30 before another hello packet is received and the dead timer is reset to 40 again. This id called the **"FULL STATE"**

![](/files/-MILBU8L5WxDKTx7-eGO)

![](/files/-MILBa-GNnUNg3-cdMb4)

### Some Show and Configuration Commands

`R1# show ip ospf neighbour`\
`R1# show ip ospf interface gi0/0`\
`R1# show ip ospf interface brief`

You can configure OSPF directly on an interface without using the `"network"` command.

`R1(config)# interface gi0/0`\
`R1(config-if)# ip ospf 1 area 0`\
`R1(config-if)# interface g1/0`\
`R1(config-if)# ip ospf 1 area 0 ......etc`

You can configure ALL interfaces as "passive" and then issue the 'no' command on interfaces that you WANT to send hello packets out from

`R1(config-router)# router ospf 1`\
`R1(config-router)# pasive-interface default`\
`R1(config-router)# no pasive-interface Gi0/0`\
`R1(config-router)# no passive-interface Gi1/0 ....etc`\
\
`R1# show ip protocol`

### QUIZ 1

![](/files/-MILFizCGd1CwC2F0rxq)

### QUIZ 2

![](/files/-MILFtr183Yc9hEqDNV3)

### QUIZ 3

![](/files/-MILGHY1MOiKUa5eqz8V)

### QUIZ 4

![](/files/-MILH6Y2BI5DdktQ_Y-b)

### QUIZ 5

![](/files/-MILHVlzVui1eCN5qd0w)

#### ExSim Question:

![](/files/-MILIQZqVqEe-RC5k7qU)

### LAB - Day 27

![](/files/-MIP8IngN8DnOPt7xjim)

![](/files/-MIOs0-SqmBDp008ksB4)

On R1 ( after step 3) we can see that OSPF shows equal cost to the 192.168.4.0/24 network via R2 and R3 even-though  via R2 goes via gigabit links. \
So step 4 on the lab we need to set a reference bandwidth where Fa interfaces have a cost of 100 and not 1 (as per default)

`R3(config-router)#auto-cost reference-bandwidth 10000 ....do to all other routers`

![](/files/-MIOwN_coWsygvlCxVsZ)

![](/files/-MIP6C53vVg6ajJqqEN4)

#### Q4

`R1(config-router)# auto-cost reference-bandwidth 10000`

#### Q5

`R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2` \
`R1(config)# router ospf 1` \
`R1(config-router) # default-information originate`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cisco.microcisco.com/icnd-1/routing/ospf-2-cost-neighbours-and-configs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
