What is OSPF?
OSPF (Open Shortest Path First) is a routing protocol that automatically finds the best route to a network. It is technically a link-state protocol, which means each router in a network has a map of the network.
The reason you use OSPF is that in a network with multiple routers, you would normally have to configure a route to each network on every router. This doesn’t sound too bad if you only have 2 or 3 routers, but what if you have 10, and the network changes frequently? This would take forever to maintain manually. OSPF does it automatically for you.
A simple way to think about OSPF is that it’s kind of like DHCP, but for routes. It helps routers dynamically exchange routing information and calculate the best paths to destinations.
How does it work?
Each router has a Link-State Database (LSDB), which contains Link-State Advertisements (LSAs). This is how the router knows about other routers and the network topology. Every 10 seconds, a router sends a HELLO message to the multicast address 224.0.0.5
to establish and maintain OSPF neighbor relationships.
Once the routers exchange information, they use Dijkstra’s algorithm to calculate the shortest path first, which ensures efficient routing. You want to make sure that a router is only connected to two areas.
What is an area?
An area is a group of routers that share a common LSDB. The reason for using areas is that if all routers were in the same area, sending a hello message would take a long time and generate unnecessary traffic. By segmenting the network into areas, OSPF reduces the overhead and optimizes communication within the network.
How to Get a Wildcard Mask
In OSPF, you often need to specify a wildcard mask when configuring the network
command. A wildcard mask is used to specify which part of an IP address is relevant for matching and which part is ignored. It’s essentially the inverse of a subnet mask. Here’s how you can calculate a wildcard mask:
Method 1: Manual Calculation (The Hard Way)
- Start with the subnet mask:
For example, if the subnet mask is255.255.255.0
, write it in binary:
11111111.11111111.11111111.00000000
- Invert the bits:
Change all1s
to0s
and all0s
to1s
. This gives you the wildcard mask:
00000000.00000000.00000000.11111111
- Convert the binary wildcard mask back to decimal:
Convert each 8-bit block from binary to decimal:
0.0.0.255
So, the wildcard mask for the subnet mask 255.255.255.0
is 0.0.0.255
.
Method 2: Easy Way (Subtract Each Octet from 255)
Alternatively, you can use this shortcut method, which is quicker:
- Subtract each octet of the subnet mask from 255:
- For
255.255.255.0
, subtract:255 - 255 = 0
255 - 255 = 0
255 - 255 = 0
255 - 0 = 255
The wildcard mask is 0.0.0.255
.
Example Wildcard Mask Calculations
- For subnet mask
255.255.255.252
, the wildcard mask is0.0.0.3
. - For subnet mask
255.255.254.0
, the wildcard mask is0.0.1.255
.
Now that you understand how to calculate the wildcard mask, you can use it when configuring OSPF or other routing protocols.
How to Configure OSPF
Now, let’s go over how to configure OSPF. We will be using this network.
You will need to configure each interface with an IP address. I’ll show you how to configure Router 1 and Router 2. If you follow the configuration of Router 2 for the other routers, it will work.
Router 1
- Enable OSPF
router ospf 1
The router command is used to enable a routing protocol. ospf is the type of protocol. 1 is the OSPF process ID. This does not have to match the other routers.
- Set the Router ID
router-id 1.1.1.1
The router-id command sets the Router ID. The router with the highest Router ID will be the main router. If the Router ID is not manually configured, OSPF will use the highest IP address of a loopback interface. If no loopback interfaces exist, it will use the highest IP address of a physical interface.
- Enable OSPF on Networks
network 10.0.12.0 0.0.0.3 area 0
- The network command tells OSPF which networks to include.
- 10.0.12.0 is the network you want OSPF to advertise.
- 0.0.0.3 is the wildcard mask. Refer above for how to calculate a wildcard mask for a network.
- area 0 specifies the OSPF area. Area 0 is the backbone area.
- Advertise the Default Route
default-information originate
- Apply the Changes
do write
Troubleshooting
I will show you some commands and explain them. Some of the stuff they show I will not talk about now but in a different blog post.
- To View OSPF neighbors
-
Command:
show ip ospf neighbor
-
Output Overview: Displays information about OSPF neighbor relationships.
-
Key Fields in the Output:
- Neighbor ID
- Priority (Pri)
- OSPF State (FULL, 2-Way, etc.)
- Dead Time (time until the neighbor is considered down)
- Neighbor IP Address
- Interface Name (local interface with which the neighbor is connected)
-
Common Usage:
- Verifying OSPF Neighbor Adjacencies
- Checking OSPF Neighbor Status (FULL/2-Way)
- Troubleshooting OSPF Neighbor Problems
- Diagnosing OSPF Dead Time and Timeouts
-
Explanation of OSPF States:
FULL
: Full OSPF adjacency established.2-Way
: OSPF adjacency established on non-broadcast or point-to-point networks.- Other states:
EXSTART
,Exchange
,Loading
, etc. (used during OSPF negotiation).
-
Neighbor States in Context:
FULL/DR
: Designated Router is elected.FULL/BDR
: Backup Designated Router is elected.2-Way
: Full adjacency is not formed but neighbor relationship exists.
-
Common Troubleshooting Scenarios:
- Identifying neighbors stuck in states like
2-Way
orExchange
. - Verifying mismatched OSPF configuration (timers, hello interval).
- Checking if dead time is expiring and causing neighbor loss.
- Identifying neighbors stuck in states like
-
Conclusion:
- Helps verify OSPF neighbor relationships and troubleshoot issues in OSPF adjacency formation.
- Show OSPF interface
-
Command:
show ip ospf interface
-
Output Overview: Displays OSPF interface configuration and status.
-
Key Fields in the Output:
- Interface Name
- Interface Status (up/down)
- Interface IP Address
- OSPF Area
- Process ID
- Router ID
- OSPF State (DR/BDR/Point-to-Point)
- Cost
- Hello Interval
- Dead Interval
- Neighbor Count
- Adjacent Neighbor Count
- Authentication
- SPF Run Count
- Last SPF Run
- OSPF Traffic Rates (5 minute, 1 minute, 10 second rates)
- Area Type (Broadcast, Point-to-Point, etc.)
- DR/BDR Addresses
- Designated Router (DR) and Backup DR (BDR)
-
Common Usage:
- OSPF Configuration Check
- Neighbor Status Check
- DR/BDR Information
- Troubleshooting OSPF Adjacency and Timer Issues
- Checking OSPF Performance (traffic rates)
-
Troubleshooting Scenario Example:
- Checking mismatched Hello and Dead Intervals between routers
-
Conclusion:
- Useful for diagnosing OSPF interface issues and verifying OSPF configuration
- Show the OSPF Database
-
Command:
show ip ospf database
-
Output Overview: Displays the OSPF Link-State Database (LSDB), which contains all the OSPF LSAs (Link-State Advertisements) that the router has received and processed.
-
Key Fields in the Output:
- LSA Type: Type of the Link-State Advertisement (LSA), such as Router LSA, Network LSA, Summary LSA, etc.
- LSA ID: The unique identifier for the LSA, typically the IP address or network address.
- Advertising Router: The Router ID of the router that generated the LSA.
- Sequence Number: The sequence number of the LSA, used to determine the freshness of the LSA.
- Age: The time elapsed since the LSA was created or last updated.
- Checksum: A checksum to verify the integrity of the LSA.
- Link-State Type: The type of network or link (e.g., Point-to-Point, Broadcast, etc.)
- Links: Lists the links advertised by the router or network, including their cost and state.
-
Common Usage:
- Verifying the OSPF LSDB contents.
- Troubleshooting OSPF routing information and LSAs.
- Checking for mismatches or outdated LSAs in the database.
- Viewing the structure of OSPF routes, including the routing table and network topology.
-
Explanation of Different LSA Types:
- Router LSA (Type 1): Contains information about the router’s directly connected interfaces and their states.
- Network LSA (Type 2): Describes the state of the broadcast or non-broadcast multi-access network, including DR/BDR information.
- Summary LSA (Type 3): Used to advertise networks from other areas (used for inter-area routing).
- AS External LSA (Type 5): Used to advertise external routes (from outside the OSPF domain).
-
Output Examples:
- Router LSA:
- Shows information about a router’s links, including interfaces, IP addresses, and cost.
- Network LSA:
- Shows information about a broadcast network, including DR and BDR.
- Summary LSA:
- Advertises inter-area routes.
- Router LSA:
-
Common Troubleshooting Scenarios:
- Identifying missing or corrupted LSAs in the LSDB.
- Verifying the presence of necessary inter-area or external routes.
- Ensuring that LSRs (Link-State Requests) are being sent correctly.
- Checking if LSAs have the correct sequence number and are not stale.
-
Conclusion:
- The
show ip ospf database
command helps you verify the OSPF LSDB, track the state of OSPF routes, and troubleshoot issues related to OSPF flooding, LSAs, and link-state changes.
- The