After reading my previous post, Configuring OSPFv2 Between Cisco and Force10, reader Paulkil suggested an article examining exactly what the
network command under a routing process does. So here it is.
network command under any IGP process configuration on IOS is generally described as being used to "turn on" a network within the routing protocol. But what does that entail? The command actually has two effects:
- Attempt to form adjacencies with neighbors attached to interfaces matched by the network statement
- Begin advertising directly-connected networks matched by the network statement.
For illustration, suppose an OSPFv2 router has three interfaces, each in a separate /24 subnet.
There are a few approaches we can take to enabling OSPF on these three interfaces.
One network statement per subnet
R1(config-router)# network 192.168.43.0 0.0.0.255 area 0
In the above example, you'll notice that the wildcard mask is the inverse of the subnet mask (255.255.255.0) for the interface. This is a common and fairly intuitive approach. We need a total of three
network commands, one per subnet, to complete our configuration.
router ospf 1 network 10.18.51.0 0.0.0.255 area 0 network 192.168.43.0 0.0.0.255 area 0 network 192.168.177.0 0.0.0.255 area 0
One network statement per interface
An extension of the prior approach, we could optionally implement interface-specific wildcard masks (0.0.0.0) instead of matching the entire subnet. This approach can be useful when you want to explicitly state which interface(s) are being enabled under the routing process.
router ospf 1 network 10.18.51.1 0.0.0.0 area 0 network 192.168.43.1 0.0.0.0 area 0 network 192.168.177.1 0.0.0.0 area 0
There is no rule which requires a one-to-one mapping of
network statements to actual networks; we are free to summarize. For example, we can summarize the two 192.168.x.x networks with a single
router ospf 1 network 10.18.51.0 0.0.0.255 area 0 network 192.168.0.0 0.0.255.255 area 0
With regard to OSPF, you cannot summarize beyond the scope of an area; if using the
network command, you will always need at least one statement per area.
Enable all interfaces by default
If all interfaces on our router are to participate in the IGP, we can simply use a single "default summarization" to enable all of them at once.
router ospf 1 network 0.0.0.0 255.255.255.255 area 0
Use this with caution. Keep in mind that this will enable not only all currently configured interfaces, but new ones as well.
Enable OSPF under interface configuration
Lastly, we can sometimes opt not to use the
network command at all. Certain protocols (RIPng, OSPFv2, OSPFv3, IS-IS) can be enabled under interface configuration mode.
R1(config-router)# interface f1/0 R1(config-if)# ip ospf 1 area 0
This happens to be my preferred approach, when supported, but your preference may differ. This method can also be combined with the
R1(config)# router ospf 1 R1(config-router)# network 192.168.0.0 0.0.255.255 area 0 R1(config-router)# R1# show ip protocols Routing Protocol is "ospf 1" Outgoing update filter list for all interfaces is not set Incoming update filter list for all interfaces is not set Router ID 18.104.22.168 Number of areas in this router is 1. 1 normal 0 stub 0 nssa Maximum path: 4 Routing for Networks: 192.168.0.0 0.0.255.255 area 0 Routing on Interfaces Configured Explicitly (Area 0): FastEthernet1/0 Reference bandwidth unit is 100 mbps Routing Information Sources: Gateway Distance Last Update 22.214.171.124 110 00:00:22 126.96.36.199 110 00:00:32 188.8.131.52 110 00:00:22 184.108.40.206 110 00:27:51 Distance: (default is 110)
There are instances where an IGP should advertise a network, but not attempt to form adjacencies on that interface. A common scenario is the access edge: exposing your routing protocols to untrusted end hosts is dangerous. In cases such as this, we can designate interfaces as passive. Passive interfaces will not form adjacencies with peers, but their attached networks will still be advertised via the routing protocol.
R1(config-router)# passive-interface f0/0
Alternatively, we could designate all interfaces as passive by default, allowing only those we explicitly designate to form adjacencies.
router ospf 1 passive-interface default no passive-interface FastEthernet1/0 network 10.18.51.0 0.0.0.255 area 0 network 192.168.0.0 0.0.255.255 area 0
Here's an example which ties together a few of the approaches we've looked at in this article:
interface FastEthernet0/0 ip address 192.168.43.1 255.255.255.0 ! interface FastEthernet0/1 ip address 192.168.177.1 255.255.255.0 ! interface FastEthernet1/0 ip address 10.18.51.1 255.255.255.0 ip ospf 1 area 0 ! router ospf 1 router-id 220.127.116.11 log-adjacency-changes passive-interface FastEthernet0/0 passive-interface FastEthernet0/1 network 192.168.0.0 0.0.255.255 area 0
All three networks will be advertised, but the router will only form OSPF adjacencies on the 10.18.51.0/24 network. We can verify this behavior with
show ip protocols.
R1# show ip protocols Routing Protocol is "ospf 1" Outgoing update filter list for all interfaces is not set Incoming update filter list for all interfaces is not set Router ID 18.104.22.168 Number of areas in this router is 1. 1 normal 0 stub 0 nssa Maximum path: 4 Routing for Networks: 192.168.0.0 0.0.255.255 area 0 Routing on Interfaces Configured Explicitly (Area 0): FastEthernet1/0 Reference bandwidth unit is 100 mbps Passive Interface(s): FastEthernet0/0 FastEthernet0/1 Routing Information Sources: Gateway Distance Last Update 22.214.171.124 110 00:10:24 126.96.36.199 110 00:10:34 188.8.131.52 110 00:02:30 184.108.40.206 110 00:02:30 Distance: (default is 110)