Routers learn network paths through either manual static route configuration or dynamic routing protocols, each with distinct trade-offs in scalability, security, and manageability. This content covers how routing tables are built and when to apply each approach.
Router Route Learning
We know your router uses routes to be able to route traffic in the proper direction, but how does it learn of those routes?
There are two ways that your router can learn of other networks and install routes into the routing table. One way is that it can dynamically learn from a dynamic routing protocol. The other way is some sort of manual configuration on that router.
So for instance, if I get onto a router and I assign an IP address, then it will learn of a directly connected network, and as long as that network interface is up, then that directly connected network will be inside the routing table. If it's IPv6, the other thing that it will add is the local route. The local, or the L on here on IPv6, is the direct IP address that you set up — notice the /128 on there. So when I set up a network on this device, it will add the directly connected network whenever that interface is up, and if it's IPv6 it'll also add the local address.
The other way that I could manually set up a route on my router is to do the ip route command and specify the network that it needs to reach and what exit interface or next hop to use to get there. So that's statically set up, that's a manual configuration. Whether I'm setting up an interface or I'm setting up a static route, we can configure that and the route gets installed in the routing table.
The other way for it to learn is through a dynamic routing protocol. If we actually configure it for something like RIP or OSPF, then as long as it's connected to other routers that are speaking essentially the same language — and maybe it's OSPF — then they'll learn from each other of all of these directly connected routes that are on these routers.
Here's an example of an IPv4 routing table. On here we can see it's very similar. We don't see the L's, the local routes, that are in there, but we see a lot of directly connected networks, so anything with the C on here is a directly connected network. We also see a couple of examples of a statically assigned route, and then we see several O's on here as well. If we need to find out what that O means, we can look up here, and O is OSPF. So we look into the legend and we can find that this router has learned of these routes on here through OSPF. The legend tells us whether it's connected, whether it's static, or learned through RIP, or learned through BGP or EIGRP, so it could learn through several of these other methods for these different routes on there.
One other thing that I'll point out there is this special out right here with the asterisk next to it. That is the default gateway or the default route. We see Gateway of Last Resort right here to network quad zero, and it's got this 10.240.0.2. That statement right here exists because it is in the routing table right here, and it's in the routing table because it's a statically assigned route on this device right here. We see that that IP address matches up with that IP address, so that is the Gateway of Last Resort or the default route that's on this router.
At this point on our network we have that demo laptop, and it is not able to ping this far distant network right here. What will happen is it's got a default gateway set up on this computer, so it'll make it to the layer 3 switch. Then the layer 3 switch doesn't know how to get to this network, and so it will end right there.
But what we could do is set up a static route that says: to get to this network, you would send it to this router right here. So we would set up that statically assigned route on this layer 3 device right here. The packet would get to this router right here, then this router would say, well, I don't know how to get to that network, so then we'd have to put a static route on here that points to this router right here. And then this router would say, I don't know how to get to that network, so we'd have to add a static route there. It would get to this red right here — it's a directly connected network — and so we'll send it to the network, and it'll reach the end device.
Let's say this is a ping and the end device is then responding back. This end device right here has a default gateway set up, so it'll make its way to its default gateway and successfully get to its default gateway. From this default gateway, it is not aware of this network that this computer is on, and so what we'd have to do is assign a static route on here that points to this router over here. Then this router would get it and would say, well, I don't know how to get there, so we'd have to assign a static route that would point to this router right here. And then this router would get it and say, I don't know what to do with that, so we'd have to create another static route that would point to this layer 3 switch.
So to facilitate this level of communication we would have to have six different routes — here's two, four, six — entered on these machines. Six different static routes, just to allow this computer to communicate to this network right here.
If we were talking about this demo Pi, we could through the same static routes make it to this network right here, but once again this router would not know how to get to the network the demo Pi is on, so we would have to have another set of static addresses, 10.1.20.024 network.
So you can see that static routes are great, we can get this up and running and communicating, but it would take quite a few routes on here. We're at nine routes already and we haven't even touched — we've only done a couple of VLANs, and we've got probably about five VLANs we would need to do with this. So we would need quite a few routes to make this all function correctly.
That's where a dynamic routing protocol could really help us out, because if we set up dynamic routing protocols on all of our layer 3 devices, what will happen is they will communicate with each other and pass routing information and network information to each other. Therefore this layer 3 device will automatically learn of this network over here, and this router right here will automatically learn of the networks attached to this layer 3 switch. That's where OSPF or RIP or EIGRP can really help us grow our network and make it more scalable, because then it could just automatically learn of these different routes and of these different networks.
Let's take a look at some of the differences between statically assigning routes and these dynamic routing protocols, which will help the routers learn of routes dynamically.
First of all, from a manageability standpoint, static routes are really easy. They're just simple lines that we can enter in there and get this communication going — until your network starts growing. As you scale up your network, this becomes increasingly difficult to manage. So from a manageability standpoint this can get difficult as it increases in size. Versus, initially a dynamic routing protocol is a little bit harder to set up. There's a little more gotchas with it and little things that you've got to be concerned about, but it's much more scalable. Once you have it set up, it scales much easier.
From a topology standpoint, if there are changes that happen, static routes are statically set, they don't change, and so you would have to go onto the equipment and actually change it if a link went down and you needed to reroute a different direction. Versus dynamic routing protocols are adaptable — when things change they automatically update. So static routes are not as scalable, versus dynamic routes can be much more scalable.
From a security standpoint, there are some issues with dynamic routing protocols. There's information that's being passed back and forth between these devices, and anytime we've got information that's being sent around, that is a way for a hacker to be able to gather information about your network and learn more about your network. So that can be a problem. Whereas with static routes there's not that same information that's being passed back and forth.
From a resource usage standpoint, these dynamic routing protocols are active, so they're taking up bandwidth, and every time changes happen it will take up memory and CPU as well. So that is possibly a downfall from the dynamic routing protocols, whereas static routes are very simplistic in how they operate.
As far as path predictability — that means that if I look at my network diagram, I know exactly how it's going to communicate and can predict where the paths are going to go across — well, you define it with static routes, and so it's pretty straightforward there. But with a dynamic routing protocol you don't have as much control over it, or you have to get in there and start configuring things so that way you can specify exactly how you want the choice of the routes to be selected.
When it comes to static routes, we use them when we're dealing with smaller, simpler networks. We use them with default routes — there are still times, even though we have dynamic routing protocols set up, when we still will set up a default static route. We use them if we have what's called stub networks, where the network doesn't continue on, it just ends at a certain point. And we use them if we want to be explicit, if we want to control the flow of data on our networks.
For the dynamic routing protocols, we use those when it becomes larger networks, or if we have things like redundancy where we want to use multiple links, or we want failover from one link to another.
TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.
Explore free tools and programs →