Help me understand the 'ip route' command for cisco routers

I made a diagram that may be helpful:

alt text

With regard to static routing, consider the above diagram. We have three separate networks: 192.168.1.0, 192.168.2.0, and 192.168.3.0. At first, network hosts (routers, computers, etc.) can only communicate with other hosts that are on their own network. For instance, the computer named James has a single interface on network 192.168.1.0, so that's the only network that it can 'see'. Initially, it will only be able to communicate with Router A.

Router A has network interfaces on the 192.168.1.0 and 192.168.2.0 networks, so those are the two networks that it can 'see'. These are the only networks Router A 'knows' about, so it can only communicate with hosts on the 192.168.1.0 and 192.168.2.0 networks. So Router A doesn't even 'know' that the 192.168.3.0 network exists. Similarly, Router B can 'see' networks 192.168.2.0 and 192.168.3.0. When you enter a route into the table, you're telling a host that there's a new network it can get to, and you're giving it the address of a gateway that it can use to get to the new network. So to be able to contact Jesus (or any other host on the 192.168.3.0 network) from Router A, you'd enter the command:

ip route 192.168.3.0 255.255.255.0 192.168.2.2
             ^             ^             ^
           network        mask         gateway

This works because Router B can 'see' both Router A and Jesus. Thanks to this routing table entry when Router A wants to reach the 192.168.3.0 network, it knows it can get there via Router B at 192.168.2.2, so it sends the packet to Router B. Router B can see the 192.168.3.0 network directly, so it forwards the packet along to Jesus at 192.168.3.11.

So, now we know how to direct router A to the 192.168.3.0 network. But what if we want James to also be able to reach the 192.168.3.0 network? Well, Router A already knows how to get there, and James can already 'see' Router A, since they're both on network 192.168.1.0. So we can just tell James to use Router A as its gateway to the 192.168.3.0 network. If James were a router instead of a computer, we'd use the command:

ip route 192.168.3.0 255.255.255.0 192.168.1.1
             ^             ^             ^
           network        mask         gateway

James would then be able to contact Jesus (or any host on the 192.168.3.0) network by forwarding the packet to 192.168.1.1 (Router A), which would then forward the packet to 192.168.2.2 (Router B) which would then forward the packet to its destination (Jesus in this case) via its directly connected interface.

Now, for Jesus to be able to respond to James, Jesus would need to have Router B set up as its gateway to the 192.168.1.0 network, and Router B would have to have Router A set up as its gateway to the 192.168.1.0 network. Then, any host on the 192.168.1.0 network would have a path to the 192.168.3.0 network and vice versa.

Hope that helps.


ip route works like ip route <these destination IPS> (via) <this ip> (Don't actually include the word "via"). So the final IP in the command is the next hop those packets should take. This could also be an interface on the router itself instead of an IP of a neighboring router which is commonly used when you have point to point connections. Routers generally only worry about the next hop in their actually routing tables (this gets more complicated with routing protocols, but don't worry about that for now). I don't think I can help you too much without actually IPs. But assuming you mean the computers on the right and the left most router it would be something like:

ip route 192.168.1.0 255.255.255.0 10.10.10.1

If your computers were all in the 192.168.1.0/24 network and 10.10.10.1 was the ip address of the interface on the middle router connected to the left most router. The left most router would need an IP like 10.10.10.2. Then the middle router would probably have 192.168.1.1 on the interface connected to the switch.

Also a good thing to remember with these labs when you start out is not only do the packets need to be routed to the destination, but the replies must be routed back properly for a ping to work.

One more way to wrap your head around this is not to think about routers so much as interfaces and the IPs they have. Routers look at a destination IP address in the packet and forward it to the right interface. The only reason you don't need to specify ip route commands within a router for all the interfaces that exist on the router is that these are entered into the routing table automatically.