What a router does with a packet
A router looks at the packet's destination address, finds the best matching route in its routing table, and sends the packet out of that route's interface. If no route matches, it drops the packet.
A new router only knows the networks on its own interfaces. Here is R1 with two interfaces up:
In NetLab
▶ R1 R1>enable R1#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + - replicated route, % - next hop override Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.0.12.0/30 is directly connected, GigabitEthernet0/1 L 10.0.12.1/32 is directly connected, GigabitEthernet0/1 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.1.0/24 is directly connected, GigabitEthernet0/0 L 192.168.1.1/32 is directly connected, GigabitEthernet0/0
| Code | Means | Comes from |
|---|---|---|
| C | Connected network | An interface with an address that is up/up |
| L | Local address (/32) | The interface's own address |
| S | Static route | Typed by an administrator |
| O | OSPF | Learned from other routers (module 14) |
| S* | Static default route | ip route 0.0.0.0 0.0.0.0 ... |
Parts of a route
A learned route looks like this:
S 192.168.3.0/24 [1/0] via 10.0.12.2
S: how the route was learned (static).192.168.3.0/24: the destination network (the prefix).[1/0]: the administrative distance (1) and the metric (0).via 10.0.12.2: the next hop: the next router to hand the packet to.
How the router picks a route
- Longest prefix match: the route with the longest prefix that contains the destination wins. A /24 beats a /16, and a /16 beats the default route /0.
- If two sources offer the same prefix, the lower administrative distance (AD) wins: it says how much the router trusts the source.
- If one source offers several paths to the same prefix, the lower metric wins. Equal metrics are all used (load balancing).
Remember: Longest match first. AD and metric only decide between routes to the same prefix.