One of the first steps you should take when configuring OSPF is to configure loopback interfaces to ensure that your Router ID matches the IP address of the loopback interface when the OSPF routing process is started. To create a virtual loopback interface, you configure it like a normal interface:
Router(config)#interface loopback 0
Router(config-if)#ip address 10.1.42.1 255.255.255.255
The interface number for the loopback interface is arbitrary because the interface is virtual. Also, notice that the subnet mask used in the loopback interface is 255.255.255.255 or a/32. This is known as a hostmask. Typically it is used on loopback interfaces because there is no need to use an entire subnet on a virtual interface that doesn’t connect to anything.
To start the OSPF process for configuration, you use the router keyword followed by OSPF, just as you have in the past with other routing protocols. In this case of OSPF, however, you must specify a process ID after the router OSPF keywords. The process ID is an arbitrary number ranging from 1 to 65535, in which the router can track whether you have multiple instances of OSPF running in your router. Because this process ID is only known on the local router that you configure, the process ID does not need to match in all router configurations.
Before we go further with the explanation of the OSPF configuration, you need to understand the means by which OSPF advertises the classless networks in the configuration. Because you no longer have the luxury of putting a classful subnet in the network statement, you need to have some way of telling the router what specific IP subnets are to be applied to the OSPF routing process. OSPF (as well as EIGRP and access lists) uses something called a wildcard mask to tell the IOS how much of an IP address should be applied to criteria in a configuration statement. Those criteria differ depending on which configuration statements the wildcard mask is using.
In the case of OSPF, the wildcard mask is used to define what portion of the IP in a network statement is to be associated with the routing process. If the IP addresses assigned to interfaces match the scope of the addresses defined with the IP address and wildcard mask criteria in the network entry, OSPF is enabled on those interfaces, and their subnets are advertised in routing updates.
Wildcard masks are represented as 32-bit numbers separated into four octets, just like IP addresses and subnet masks. Each bit in the wildcard corresponds to the same bit position in the IP address to identify whether that bit should be applied to the criteria. Specifically, if the bit value in a wildcard mask is 0, the corresponding bit in the IP address is checked and applied to the criteria. Conversely, a 1 in a wildcard mask bit signifies that the corresponding bit in the IP address can be ignored. Using these 0s and 1s, you are basically telling the IOS to perform pattern matching against the IP address that precedes the wildcard mask and to apply the portion that matches the conditions in the configuration statement.
For example, if you wanted to apply a wildcard mask to specify an IP address, every bit in the wildcard mask must be a 0 (0000000.0000000.0000000.0000000), because each corresponding bit in the IP address is being applied to the criteria. So, for example, if you wanted to specify the IP address of 10.1.4.2, the corresponding wildcard mask for that specific IP would be 0.0.0.0 in decimal. On the contrary, if you wanted to apply the criteria to any IP (therefore, you do not care whether any of the corresponding bits match), you would need to have a wildcard mask composed of all 1s (11111111.11111111.11111111.11111111, or 255.255.255.255 in decimal). Technically, it does not matter which IP address precedes this wildcard mask, because you are applying any value, so it is common to use an IP address of 0.0.0.0 with the 255.255.255.255 wildcard mask.
In cases such as those with OSPF, you need to use wildcard masks to specify a specific IP subnet. For instance, given an IP subnet of 192.168.1.0/24, you know that you want to apply the criteria to the first 24 bits in the IP address. Because the last octet of the IP subnet can be of any value from 0 to 255, you don’t want to apply any of those bits to your criteria. The resultant wildcard mask ultimately is composed of the first three octets in the wildcard mask, containing all 0s to match the 192.168.1, and the last octet, containing all 1s. thus, 192.168.1.0/24 subnet would be identified as 192.168.1.0.0.0.0.255 in the configuration statement.
That may seem fairly cut and dried, but how do you apply a wildcard mask to a subnet such as 192.168.1.4/30? You know that the first three octets will have all 0s, but you can’t say you don’t care about all 8 bits in the last octet, because you want to apply this criterion to only the IPs in the 192.168.1.4 255.255.255.252 subnet (192.168.1.4 to 192.168.1.7). as shown in the picture below, by breaking the last octet into binary, you can see how to align the corresponding bits in the wildcard mask. Namely, the first 6 bits in the last octet must be exactly the same values that are in the IP address to give you a decimal value of 4. The last 2 bits can be any combination of 1s or 0s because they will ultimately give you the values of 192.168.1.4, 192.168.1.5, 192.168.1.6, and 192.168.1.7. Because the first 6 bits must match, and the last two do not matter, the wildcard mask in binary for the last octet is 00000011, or 3 in decimal. So, to specify the 192.168.1.4/30 subnet, your statements would look like 192.168.1.4 0.0.0.3.
Notice in the above picture that the wildcard mask happens to be the inverse of the subnet mask.
For this very reason, the wildcard mask is sometimes called the inverse mask. This is the case for all wildcard masks that correspond to an entire subnet.
OSPF Network configuration
Reverting to the matter of configuring OSPF, you left off with entering the OSPF routing process by entering something similar to the following:
Router(config)#router ospf 4
Recall that the number 4 in this example is the process ID and does not have to match in all routers. Because you are in the routing process (indicated by the Router(config-router)#prompt) for OSPF, you ready to specify the classless networks that are to participate in OSPF. As you do with other routing protocols, you start by using the keyword network, but from there you go in a different direction. At this point, you need to specify an IP address or IP subnet, followed by the wildcard mask to identify which interfaces are participating in the OSPF process. Immediately following the IP and wildcard mask is the keyword area, followed by the OSPF area number where the router’s interface is located. For example, if you have an IP address of 192.168.1.1 with a subnet mask of 255.255.255.0 connected to area 0, you would configure it something like this:
Router(config)#router ospf 4
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Because you use the wildcard mask in the OSPF configuration, you actually have multiple ways to specify an interface and its subnet in the OSPF routing process. Using the same example, you could use any of the configurations shown in the table below to place that interface in area 0.
|Router(config-router)#network 192.168.1.1 0.0.0.0 area 0
|The interface with an IP address of 192.168.1.1 and its subnets are advertised in OSPF.
|Router(config-router)#network 192.168.0.0 0.0.255.255 area 0
|Interfaces and their subnets starting with 192.168 are advertised in OSPF.
|Router(config-router)#network 192.0.0.0 0.255.255.255 area 0
|Interfaces and their subnets starting with 192 are advertised in OSPF
|Router(config-router)#network 0.0.0.0. 255.255.255.255 area 0
|All interfaces and their subnets are advertised in OSPF.
The following picture shows the configuration for two of the routers in the multi-area OSPF autonomous system. First, notice that Router B and Router D do not have matching Router IDs. These values are significantly locally only to those routers to keep track of multiple instances of OSPF that might be running. Router D has both interfaces in the backbone area, so you specify each subnet, using the appropriate wildcard mask, and identify the networks to be in the area 0. Notice that the configurations parameters are similar in Router B, except the interface that has the 192.168.1.8 subnet assigned to it is in Area 51. With that network placed in a different area, that router is now configured to be an ABR.
Additional OSPF commands
As you know, OSPF is loaded with additional features and capabilities that make this routing protocol extremely adaptable. Throughout the course of your Cisco career, you may find yourself needing to configure additional parameters to fit the needs of your network. We’ll cover a few of the many configurations that OSPF offers.
For instance, in instances where you want to designate your area as a stub to decrease the amount of routing information stored in the topology database, you can use the area command in the routing process to identify that area as a stub:
Router(config-router)#area 51 stub
Because OSPF does not have automatic summarization, you have to configure these routers manually to summarize a set of networks. For example, if you wanted to summarize the 192.168.1.4/24 to 192.168.1.7/24 subnets in Area 51, you would use the range keyword in the area configuration, as in the following:
Router(config-router)#area 51 range 192.168.1.4 255.255.255.0
Similar to RIP, suppose your local router has a default route configured, and you want to redistribute that default route into OSPF so that other routers will dynamically learn the default route via OSPF updates. You would use the default-information originate command in the routing configuration.
OSPF also has several commands that are actually configured on the interfaces as opposed to in the routing process. For example, if you wanted to manipulate the cost of an interface to make a network favorable over another or to force the router to load balance, you could use the IP OSPF cost command:
Router(config)#interface serial 0/0
Router(config-if)#ip ospf cost 2
On interfaces that are connected to broadcast and nonbroadcast multi-access topologies, it is highly recommended that you change the priority in the routers in which you want to force the DR and BDR election. By default, the priority is 1, but you can change that manually by using the IP OSPF priority command as follows:
Router(config)#interface serial 0/0
Router(config-if)#ip ospf priority 3