Subnet Masks in OSPF Network Statements

In a comment to my recent NTP-related post mentioning OSPF configuration, Wan Tajuddin correctly stated that the OSPF network statement should contain the wildcard bits, not the subnet mask. However, I was positive I had running networks with the network 0.0.0.0 0.0.0.0 area 0 OSPF configuration, so it was time for one more lab test. As it turns out, Cisco IOS started accepting either the wildcard bits or the subnet mask in the network OSPF configuration command.

Here is the printout from the test run. First, the traditional configuration:

R1#show run ¦ sect router ospf
router ospf 1
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0
R1#show ip ospf interface brief
Interface    PID   Area  IP Address/Mask    Cost  State Nbrs F/C
Lo0          1     0     10.0.1.1/32        1     LOOP  0/0
Se1/1        1     0     10.0.7.5/30        70    P2P   1/1
Se1/0        1     0     10.0.7.1/30        64    P2P   1/1
Fa0/0        1     0     10.0.0.1/24        10    WAIT  0/0

The configuration uses the wildcard bits, and all interfaces are in area 0 as expected. Now let's try to specify the 0.0.0.0/0 network:

R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no router ospf 1
Mar 1 00:09:37.640: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.3 on Serial1/1 from FULL to DOWN, Neighbor Down: Interface down or detached
Mar 1 00:09:37.648: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.2 on Serial1/0 from FULL to DOWN, Neighbor Down: Interface down or detached
R1(config)#router ospf 1
R1(config-router)#network 0.0.0.0 0.0.0.0 area 0
R1(config-router)#^Z
R1#
Mar 1 00:09:50.944: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.3 on Serial1/1 from LOADING to FULL, Loading Done
Mar 1 00:09:51.104: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.2 on Serial1/0 from LOADING to FULL, Loading Done
R1#show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Lo0        1    0      10.0.1.1/32    1 LOOP  0/0
Se1/1      1    0      10.0.7.5/30   70 P2P   1/1
Se1/0      1    0      10.0.7.1/30   64 P2P   1/1
Fa0/0      1    0      10.0.0.1/24   10 WAIT  0/0

OK, it works for the all IP addresses prefix (default route). How about a specific subnet (10.0.7.0/24)?

R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no router ospf 1
Mar 1 00:09:37.640: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.3 on Serial1/1 from FULL to DOWN, Neighbor Down: Interface down or detached
Mar 1 00:09:37.648: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.2 on Serial1/0 from FULL to DOWN, Neighbor Down: Interface down or detached
R1(config)#router ospf 1
R1(config-router)#network 10.0.7.0 255.255.255.0 area 0
R1(config-router)#^Z
R1#
Mar 1 00:09:50.944: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.3 on Serial1/1 from LOADING to FULL, Loading Done
Mar 1 00:09:51.104: %OSPF-5-ADJCHG: Process 1, Nbr 10.0.1.2 on Serial1/0 from LOADING to FULL, Loading Done
R1#show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Se1/1       1    0     10.0.7.5/30   70   P2P  1/1
Se1/0       1    0     10.0.7.1/30   64   P2P 1/1

As expected, only the WAN interfaces with IP addresses in the specified IP address range are in the OSPF process – Cisco IOS correctly recognizes IP prefix specifications, including subnet masks.

OK, but let’s see how the router stores the OSPF configuration:

R1#show running-config ¦ section router ospf
router ospf 1
 log-adjacency-changes
 network 10.0.7.0 0.0.0.255 area 0

Cool. The router automatically inverts the subnet mask into wildcard bits, so even if you use the “wrong” format on the CCIE lab, the automatic grading program will get the expected results :)

Further reading:

8 comments:

  1. Good morning,

    The thing with the OSPF network wildcard is not about matching subnets, it is meant to match the IP's associated with the interfaces.
    If the interface IP is within the specified network with wildcard mask , OSPF is enabled on that interface.

    That's just how OSPF knows in which interfaces it should run.
  2. You're absolutely right, I was yet again skipping the basics and jumping to the juicy part.

    I've changed the wording slightly, maybe it's less misleading now. I've also included links to a few previous posts on the same topic (unfortunately Blogger can't do that on its own regardless of Google's promises made on April 1st :).

    And, most importantly, thanks for keeping me honest!
    Ivan
  3. Selling that minor feature as AI is so overrated that I think Cisco should hire you in Sales :-)
  4. 'Product marketing' would be a better department :))
  5. Ivan,

    This has been around for many years.. I would venture to say since 11.2 or earlier. I'm pretty sure I learned about it during an ICRC or ACRC class at Chesapeake Computer Consultants in the 90s. Cisco AI has been a staple for a decade! :)

    Jeremy Filliben
  6. I found out a reason not to use network 0.0.0.0 0.0.0.0

    In the Cisco Network Academys Cisco Network Simulator, Packetracer 4.11 the command doesn't work. :)

    You have put in matching network statements for the interfaces you want included in your OSPF process!

    PacketTracer isn't featureriffic, but if you want to check something simple very quickly without having to power up and cable your rack and wait for your old 2511 to finally boot up, its not a bad little tool.

    Cheers
    Shaun
  7. I actually started to notice the "intelligence" under EIGRP first (three years ago perhaps?). When you configure EIGRP today you can choose either way and the IOS would know what to put in. For example, if you type in either of the following:

    router eigrp 333
    network 10.1.0.0 255.255.0.0

    or

    router eigrp 333
    network 10.1.0.0 0.0.255.255

    The resulting EIGRP config would display "network 10.1.0.0 0.0.255.255" under router EIGRP.

    I didn't bother trying it under OSPF because I was taught, since the beginning, to enter OSPF network mask the "right" way.
  8. some thing like %ospf-5-adj
Add comment
Sidebar