Advertising loopback interfaces in OSPF

Loopback interfaces are a very convenient method to experiment with connectivity on routing labs. We use them often, but how should we advertise them? Let’s take a look on the possible ways:

  • redistributing connected interfaces, preferably with a specific route map, permitting the loopbacks only
  • using the ip ospf instance-id area area-id command in the loopback interface view
  • using the net x.x.x.x y.y.y.y area z command in the router ospf view

There are some subtle differences in implementing each method. Let’s experiment and see what they are!

First and foremost, unless you run IOS 12.4 or newer, you won’t be able to use the interface view command “ip ospf instance-id area area-id“. However, I think this is the cleanest and best way of applying areas on interfaces, and do recommend using it, so you should consider updating your software.

Let’s look at the topology we’ll be using for this lab:

Three-router topology using OSPFAs you can see, we have a simple topology with 3 routers, the router’s loopback interfaces, and the method for loopback inclusion each router will be using.

The following is the initial config for the devices, specifically for router 1. The others are equivalent.

interface Loopback0
 ip address 1.1.1.1 255.255.255.0
!
interface FastEthernet0/0
 ip address 192.168.0.1 255.255.255.0
 ip ospf 1 area 0
 duplex auto
 speed auto
!
router ospf 1
 log-adjacency-changes

Now let’s configure router 1 – create a route map that permits only the loopback0 interface and apply it to the redistribution of the connected interfaces in OSPF:

R1(config)#route-map Lo0 permit 10
R1(config-route-map)#match interface lo0
R1(config-route-map)#exit
R1(config)#

R1(config)#router ospf 1
R1(config-router)#redistribute connected subnets route-map Lo0

Let’s see the effect this had on the devices. Let’s look at R1′s topology, and then at a neighbor device.

R1#sh ip ospf database

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

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         138         0x80000003 0x0074DD 1
2.2.2.2         2.2.2.2         454         0x80000003 0x00301B 1
3.3.3.3         3.3.3.3         422         0x80000002 0x00F34F 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
192.168.0.1     1.1.1.1         421         0x80000002 0x001995

                Type-5 AS External Link States

Link ID         ADV Router      Age         Seq#       Checksum Tag
1.1.1.0         1.1.1.1         138         0x80000001 0x00A5F3 0

R2#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
O E2    1.1.1.0 [110/20] via 192.168.0.1, 00:00:27, FastEthernet0/0
     2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

The route towards 1.1.1.1 has appeared as an external OSPF route of type 2. Redistributed routes become OSPF external type 2 routes by default. The default cost or metric of a redistributed route is 1 for BGP and 20 for all other protocols. This may, or may not be what you’re expecting as a cost for that route. Be careful – routes are redistributed in OSPF as either type 1 (E1) routes or type 2 (E2) routes, with type 2 being the default. A type 1 route has a metric that is the sum of the internal OSPF cost and the external redistributed cost. A type 2 route has a metric equal only to the redistributed cost. If routes are redistributed into OSPF as type 2 then every router in the OSPF domain will see the same cost to reach the external networks. If routes are redistributed into OSPF as type 1, then the cost to reach the external networks could vary from router to router. Let’s change the type to Type 1 and see how the cost changes:

R1(config)#router ospf 1
R1(config-router)#redistribute connected subnets route-map Lo0 metric-type 1

R3#sh ip route ! some of the following output omitted
     1.0.0.0/24 is subnetted, 1 subnets
O E1    1.1.1.0 [110/21] via 192.168.0.1, 00:01:12, FastEthernet0/0

So the cost has changed from 20 to 21, because of the default OSPF cost for a FastEthernet interface being 1, and the route is 1 hop away.

This is great and all, but if for some reason you need this route to be present in a stub area, for example you need a specific /32 route to this specific host, you need to use another method. This is because stub areas block Type5 external routes, remember?

Let’s see what else we can get by not using redistribution:

R2(config)#int lo0
R2(config-if)#ip ospf 1 area 0

R2#sh ip ospf database

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

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         219         0x80000003 0x0074DD 1
2.2.2.2         2.2.2.2         41          0x80000004 0x00F937 2
3.3.3.3         3.3.3.3         503         0x80000002 0x00F34F 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
192.168.0.1     1.1.1.1         502         0x80000002 0x001995

                Type-5 AS External Link States

Link ID         ADV Router      Age         Seq#       Checksum Tag
1.1.1.0         1.1.1.1         219         0x80000001 0x00A5F3 0

R1#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 192.168.0.2, 00:00:50, FastEthernet0/0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

As we can see, this time there is no type 5 router for the route we advertised. Also, the other router receives it as an intra-area route. Let’s see the routes we’ve define up until now, on the device we’re about to advertise on:

R3#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
O E1    1.1.1.0 [110/21] via 192.168.0.1, 00:01:55, FastEthernet0/0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 192.168.0.2, 00:01:55, FastEthernet0/0
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

R1′s loopback is an external type 1 route, and R2′s loopback is an intra-area route. Nice. Let’s configure the third router:

R3(config-router)#net 3.3.3.3 0.0.0.0 area 0

R1#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 192.168.0.2, 01:05:17, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/2] via 192.168.0.3, 01:05:17, FastEthernet0/0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

So, using the net statement, we get the same result as using the ip ospf x area y statement – an intra-area route. So, to sum up all our work, here are the final routing tables of all three devices:

R1#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 192.168.0.2, 01:05:17, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/2] via 192.168.0.3, 01:05:17, FastEthernet0/0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

R2#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
O E2    1.1.1.0 [110/20] via 192.168.0.1, 01:06:09, FastEthernet0/0
     2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/2] via 192.168.0.3, 01:06:09, FastEthernet0/0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

R3#sh ip route
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
O E2    1.1.1.0 [110/20] via 192.168.0.1, 01:06:12, FastEthernet0/0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 192.168.0.2, 01:06:12, FastEthernet0/0
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
C    192.168.0.0/24 is directly connected, FastEthernet0/0

One single scenario remains – what is we don’t advertise the loopbacks into area 0, but rather each loopback in its own area? Simple – we’d get the loopback routes as inter-area routes (O IA in the routing table).

I hope this lab helps in better understanding the inclusion of loopbacks in your labs.

  • Rai

    Thank you … this is very helpful and right to the point.