Cisco: OSPF Howto

From OnnoWiki
Jump to navigation Jump to search

Sumber: https://www.techrepublic.com/article/how-to-configure-basic-ospf/



Open shortest path first, or OSPF, is a routing protocol that's based on open standards, meaning any vendor can implement its features. For years Cisco, Juniper, and other major networking vendors have coupled OSPF into their platform. When you configure OSPF, there are a few fundamental requirements in order to exchange routing information. To begin with, OSPF uses a Hello mechanism to detect neighboring devices that run OSPF. Once detected OSPF attempts to form an adjacency. Once an adjacency is established Link-State Advertisements (LSA) are used to exchange routing information.

The Hello packet is one of the first things you should have a solid understanding of. The following image shows the format of a Hello packet: 1.jpg Image: Brandon Carroll/TechRepublic

This packet is used by the Hello protocol, which is responsible for establishing and maintaining neighbor relationships. The Hello protocol also ensures that communication between neighbors is bidirectional. These packets get sent out of an interface where OSPF is enabled on a periodic basis. If a router receives a packet and sees its own address listed it knows that bidirectional communication exists. Once bidirectional communication is established a Designated Router (DR) is selected if on a multiaccess network. We're not going to cover that process in this article, however we highlight it because it's an integral part of OSPF. After two devices neighbor up, they synchronize Link-State databases.

SEE: 20 quick tips to make Linux networking easier

To configure basic OSPF to form a neighbor adjacency on a Cisco router perform the following:

   Identify the network interfaces that should run OSPF.
   Identify the OSPF area
   Issue the required commands to enable OSPF

Let's assume the following topology in which we are using OSPF area 5 and ABR5 and R5 are pre-configured for us. We need to enable OSPF on R6. 2.jpg Image: Brandon Carroll/TechRepublic

Start by entering OSPF configuration mode. You'll need to identify OSPF by a process ID. In this case, it's 1.

R6>en
R6#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R6(config)#router ospf 1
R6(config-router)#

Next, issue the network statement for each interface that should run OSPF. According to our network topology we will enable OSPF on interface g0/1 and g0/2. The network statement format is as follows:

network X.X.X.X W.W.W.W area A

In this syntax, the X.X.X.X indicates the network address. The W.W.W.W is the wildcard mask. The A is the area ID.

R6(config-router)#network 10.0.0.80 0.0.0.3 area 5
R6(config-router)#network 10.0.0.84 0.0.0.3 area 5
R6(config-router)#

A simple way to identify the wildcard mask is to subtract the subnet mask in the last octet from 255. In this case 255 - 252 - 3 so our wildcard mask is going to end in .3.

We now need to verify that OSPF has neighbored up and synchronized databases. To do so, issue the show ip ospf neighbors command.

R6#sh ip ospf neighbor

` Neighbor ID Pri State Dead Time Address Interface` 192.168.0.10 1 FULL/DR 00:00:35 10.0.0.85 GigabitEthernet0/2` 192.168.0.9 1 FULL/BDR 00:00:31 10.0.0.81 GigabitEthernet0/1` R6#`

As we can tell from the output, we have two neighbors. The Neighbor ID is not the IP address that we neighbored with. It's the Router ID selected by OSPF when the protocol was enabled. This can be chosen automatically or you can manually set this value.

Next let's look at our Link-State Database on R6.

R6#show ip ospf database 
OSPF Router with ID (10.0.0.86) (Process ID 1)

Router Link States (Area 5) 

Link ID         ADV Router      Age         Seq#       Checksum Link count
10.0.0.86       10.0.0.86       164         0x80000003 0x00EFF7 2
192.168.0.9     192.168.0.9     165         0x80000006 0x00A12F 2
192.168.0.10    192.168.0.10    229         0x80000006 0x00CC76 3

Net Link States (Area 5)

Link ID         ADV Router      Age         Seq#       Checksum
10.0.0.78       192.168.0.10    1598        0x80000004 0x004B3D
10.0.0.82       10.0.0.86       164         0x80000001 0x00C7E5
10.0.0.85       192.168.0.10    229         0x80000001 0x008313

Summary Net Link States (Area 5)

Link ID         ADV Router      Age         Seq#       Checksum
10.0.0.4        192.168.0.9     1630        0x80000004 0x00A217
10.0.0.8        192.168.0.9     1630        0x80000004 0x007046
10.0.0.12       192.168.0.9     1630        0x80000004 0x00486A
10.0.0.16       192.168.0.9     1630        0x80000004 0x00208E
10.0.0.20       192.168.0.9     1630        0x80000004 0x00F7B2
10.0.0.24       192.168.0.9     1630        0x80000004 0x00C5E1
10.0.0.28       192.168.0.9     1630        0x80000004 0x00A7FA
10.0.0.32       192.168.0.9     1630        0x80000004 0x007F1F
10.0.0.36       192.168.0.9     1630        0x80000004 0x005743
10.0.0.40       192.168.0.9     1630        0x80000004 0x002572
10.0.0.44       192.168.0.9     1630        0x80000004 0x00078B
10.0.0.48       192.168.0.9     1630        0x80000004 0x00DEAF
10.0.0.52       192.168.0.9     1630        0x80000005 0x00B4D4
10.0.0.56       192.168.0.9     1630        0x80000004 0x008EF7
10.0.0.60       192.168.0.9     1630        0x80000004 0x007011
10.0.0.64       192.168.0.9     1630        0x80000004 0x00344B
10.0.0.68       192.168.0.9     1630        0x80000005 0x001465
10.0.0.72       192.168.0.9     1630        0x80000004 0x00E393
192.168.0.1     192.168.0.9     1630        0x80000004 0x0099C1
192.168.0.2     192.168.0.9     1630        0x80000004 0x0099BF
192.168.0.3     192.168.0.9     1630        0x80000004 0x008FC8
192.168.0.4     192.168.0.9     1630        0x80000004 0x007BDC
192.168.0.5     192.168.0.9     1630        0x80000004 0x0071E5
192.168.0.6     192.168.0.9     1630        0x80000004 0x0071E3
192.168.0.8     192.168.0.9     1630        0x80000005 0x005102
192.168.0.9     192.168.0.9     1630        0x80000004 0x003F15
R6# 

Comparing database with R5, specifically the sequence numbers, we can see that we are synchronized:

R5#sh ip ospf database 

OSPF Router with ID (192.168.0.10) (Process ID 1) 

Router Link States (Area 5)

Link ID         ADV Router      Age         Seq#       Checksum Link count
10.0.0.86       10.0.0.86       193         0x80000003 0x00EFF7 2
192.168.0.9     192.168.0.9     194         0x80000006 0x00A12F 2
192.168.0.10    192.168.0.10    257         0x80000006 0x00CC76 3

Net Link States (Area 5) 

Link ID         ADV Router      Age         Seq#       Checksum
10.0.0.78       192.168.0.10    1626        0x80000004 0x004B3D
10.0.0.82       10.0.0.86       193         0x80000001 0x00C7E5
10.0.0.85       192.168.0.10    257         0x80000001 0x008313

Summary Net Link States (Area 5)

Link ID         ADV Router      Age         Seq#       Checksum
10.0.0.4        192.168.0.9     1658        0x80000004 0x00A217
10.0.0.8        192.168.0.9     1658        0x80000004 0x007046
10.0.0.12       192.168.0.9     1658        0x80000004 0x00486A
10.0.0.16       192.168.0.9     1658        0x80000004 0x00208E
10.0.0.20       192.168.0.9     1658        0x80000004 0x00F7B2
10.0.0.24       192.168.0.9     1658        0x80000004 0x00C5E1
10.0.0.28       192.168.0.9     1658        0x80000004 0x00A7FA
10.0.0.32       192.168.0.9     1658        0x80000004 0x007F1F
10.0.0.36       192.168.0.9     1658        0x80000004 0x005743
10.0.0.40       192.168.0.9     1658        0x80000004 0x002572
10.0.0.44       192.168.0.9     1658        0x80000004 0x00078B
10.0.0.48       192.168.0.9     1658        0x80000004 0x00DEAF
10.0.0.52       192.168.0.9     1658        0x80000005 0x00B4D4
10.0.0.56       192.168.0.9     1658        0x80000004 0x008EF7
10.0.0.60       192.168.0.9     1658        0x80000004 0x007011
10.0.0.64       192.168.0.9     1658        0x80000004 0x00344B
10.0.0.68       192.168.0.9     1658        0x80000005 0x001465
10.0.0.72       192.168.0.9     1658        0x80000004 0x00E393
192.168.0.1     192.168.0.9     1658        0x80000004 0x0099C1
192.168.0.2     192.168.0.9     1658        0x80000004 0x0099BF
192.168.0.3     192.168.0.9     1658        0x80000004 0x008FC8
192.168.0.4     192.168.0.9     1658        0x80000004 0x007BDC
192.168.0.5     192.168.0.9     1658        0x80000004 0x0071E5
192.168.0.6     192.168.0.9     1658        0x80000004 0x0071E3
192.168.0.8     192.168.0.9     1658        0x80000005 0x005102
192.168.0.9     192.168.0.9     1658        0x80000004 0x003F15

Finally, let's look to see if we have OSPF routes populating our routing table on R6:

R6#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
   D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
   N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
   E1 - OSPF external type 1, E2 - OSPF external type 2
   i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
   ia - IS-IS inter area, * - candidate default, U - per-user static route
   o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
   a - application route
replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set

  10.0.0.0/8 is variably subnetted, 23 subnets, 2 masks
O IA     10.0.0.4/30 [110/4] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.8/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.12/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.16/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.20/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.24/30 [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.28/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.32/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.36/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.40/30 [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.44/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.48/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.52/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.56/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.60/30 [110/4] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.64/30 [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.68/30 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     10.0.0.72/30 [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O        10.0.0.76/30 [110/2] via 10.0.0.85, 00:06:30, GigabitEthernet0/2
  [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
C        10.0.0.80/30 is directly connected, GigabitEthernet0/1
L        10.0.0.82/32 is directly connected, GigabitEthernet0/1
C        10.0.0.84/30 is directly connected, GigabitEthernet0/2
L        10.0.0.86/32 is directly connected, GigabitEthernet0/2
  192.168.0.0/32 is subnetted, 9 subnets
O IA     192.168.0.1 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.2 [110/4] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.3 [110/4] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.4 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.5 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.6 [110/4] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.8 [110/3] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O IA     192.168.0.9 [110/2] via 10.0.0.81, 00:05:24, GigabitEthernet0/1
O        192.168.0.10 [110/2] via 10.0.0.85, 00:06:30, GigabitEthernet0/2
R6# 

As you can tell, we are receiving OSPF routes. In fact, we are receiving more routes to destinations that we don't see in our topology. This is because we are only focusing on a small part of the topology. What we don't see is that ABR5 is connected to several other routers forming a backbone and exchanging routes between other areas. This obviously leads to more questions about OSPF, however, as it stands we have configured basic OSPF and can now route traffic on R6.



Referensi


Pranala Menarik