VMware ESXi and vSphere Cluster Management
IP Routing Explained
Learn how hosts and routers forward IP packets between subnets using default gateways, routing tables, interfaces, next hops, and route selection.
IP routing is the Layer 3 process of forwarding packets from one IP network to another. A router examines a packet's destination IP address, consults its routing table, and sends the packet through the appropriate outgoing interface.
This lesson explains how a host decides whether a destination is local or remote, how default gateways work, how routers select routes, and how to interpret basic Cisco IOS routing information.
What IP routing does
An IP network is a logical network identified by an address and a prefix length, such as 192.168.10.0/24. A subnet is an IP network segment defined by that network address and prefix length.
Communication between devices on the same subnet is local delivery. The devices can normally exchange Ethernet frames directly through the local LAN. Communication with a device on a different subnet is remote delivery. The traffic must cross one or more routers.
A router is a Layer 3 device that chooses paths and forwards packets between IP networks. Routing does not mean that the router sends a packet directly to every final host. Instead, each router forwards the packet to the next suitable destination along the path.
| Device | Destination classification or lookup | Action | Forwarding result |
|---|---|---|---|
| Source host | Compares the destination IP with its own IP address and subnet mask | Determines whether the destination is local or remote | Sends locally, or sends remote traffic to the default gateway |
| Router | Looks up the destination IP in its routing table | Selects the best matching route | Sends the packet through the selected outgoing interface or next hop |
| Destination host | Recognizes its own IP address | Accepts the packet | Delivers the data to the appropriate upper-layer process |
How a host identifies local and remote destinations
A host uses three important values when sending IPv4 traffic: its own IP address, its subnet mask or CIDR prefix length, and the destination IP address.
The subnet mask divides an address into a network portion and a host portion. The host applies its mask to both its own address and the destination address. If the resulting network addresses are equal, the destination is on the same subnet. If they differ, the destination is remote.
Local delivery
Suppose Host A has address 192.168.10.25/24 and wants to reach 192.168.10.60. Both addresses belong to 192.168.10.0/24, so Host A treats the destination as local.
For local delivery, Host A attempts to learn the destination device's Layer 2 address, commonly with ARP. It then places the IP packet inside an Ethernet frame addressed to the destination host and sends the frame on the local network. A router is not needed to make this local-subnet decision.
Remote delivery
Now suppose Host A has address 192.168.10.25/24 and wants to reach 192.168.20.50. The destination belongs to 192.168.20.0/24, which differs from Host A's local network. Host A therefore treats the destination as remote.
Host A sends the frame to its configured default gateway. The IP packet still contains 192.168.20.50 as its destination IP address. The gateway is only the next Layer 3 step; it is not necessarily the final destination.
Default gateways
A default gateway is the local router interface a host uses to reach remote IP networks. The gateway must be reachable on the host's own subnet. For example, a host at 192.168.10.25/24 could use 192.168.10.1 as its gateway because that address is in 192.168.10.0/24.
A host's basic TCP/IP configuration normally includes:
- IP address: the host's Layer 3 address.
- Subnet mask or prefix length: identifies the host's local subnet.
- Default gateway: the local router address used for remote traffic.
If a host has no usable default gateway, it may still communicate with devices on its own subnet, but it normally cannot initiate communication with a different subnet.
How a router forwards a packet
- The source host determines that the destination is remote.
- The source host creates an Ethernet frame addressed to the default gateway's local interface and places the IP packet inside it.
- The router receives the frame on an input interface.
- The router removes the incoming Layer 2 frame header and examines the destination IP address in the Layer 3 packet.
- The router performs a route lookup in its routing table.
- The selected route identifies an outgoing interface and, when needed, a next-hop router.
- The router creates a new Layer 2 frame for the next link and forwards the packet through the selected egress interface.
The Layer 2 framing is rebuilt at every routed hop because each link can use different local addressing information. The Layer 3 destination IP remains the basis for routing decisions as the packet travels toward its destination.
At the final subnet, the last router sends a frame toward the destination host. The destination host accepts the packet because its own IP address matches the packet's destination address.
Routing tables
A routing table is a router's list of known destination networks and forwarding information. A route commonly contains:
- Destination network or prefix: the network that can be reached.
- Prefix length or mask: specifies how specific the destination match is.
- Next hop: the next router or forwarding address, when one is required.
- Outgoing interface: the router interface used to send the packet.
- Route source: how the router learned the route, such as connected, static, or dynamic.
For each packet, the router compares the destination IP address with the route prefixes in the table. It then selects the best matching route. The selected route tells the router where to send the packet next.
Example routing-table entries
| Route code | Destination prefix | Next hop or interface | Meaning |
|---|---|---|---|
| C | 10.0.0.0/8 | FastEthernet0/1 | The network is directly connected to this active interface |
| S | 172.16.20.0/24 | 192.168.1.2 | A manually configured static route uses the listed next hop |
| R or another protocol code | 192.168.50.0/24 | 10.0.0.2 | The route was learned through a dynamic routing protocol |
| S* | 0.0.0.0/0 | 192.168.1.1 | A static default route is available for otherwise unmatched destinations |
Directly connected routes
A router automatically installs a directly connected route when an addressed interface is active and attached to a network. The router knows that network is reachable through that interface without needing a static route or routing protocol.
In Cisco routing-table output, the code C identifies a directly connected network route. For example, a route for 10.0.0.0/8 associated with FastEthernet0/1 means that traffic matching the prefix can be sent out that interface.
R1# show ip route
C 10.0.0.0/8 is directly connected, FastEthernet0/1
This entry exists because the matching network is configured on an active router interface. If the interface is down or has incorrect addressing, the expected connected route may not appear or may not be usable.
Other route sources
| Route type | How it is learned | Typical use | Routing-table identification |
|---|---|---|---|
| Connected | Automatically created from an active, addressed interface | Reach networks physically attached to the router | C in Cisco IOS |
| Static | Manually configured by an administrator | Small, predictable topologies or specific traffic-engineering choices | S in Cisco IOS |
| Dynamic | Learned and maintained through a dynamic routing protocol | Networks where paths can change or many routes must be exchanged | Protocol-specific code, such as a code for the selected protocol |
| Default | Configured as a fallback route | Send traffic for destinations with no more-specific match toward an upstream router | Often shown as S* when it is a static default route |
Connected, static, and dynamically learned routes can all appear in a routing table and be considered during forwarding. Route preference can matter when different sources offer routes to the same prefix, but the central decision begins with matching the destination prefix.
Route selection and longest-prefix matching
Longest-prefix matching means selecting the most specific route that matches a destination IP address. A longer prefix has more fixed network bits and therefore describes a smaller, more specific range of addresses.
For example, assume a router has these routes:
10.0.0.0/8throughFastEthernet0/110.20.0.0/16throughFastEthernet0/20.0.0.0/0through a next-hop router
A packet for 10.20.5.10 matches all three ranges, but 10.20.0.0/16 is the longest and most specific match. The router uses the interface associated with that route.
A default route is written as 0.0.0.0/0 for IPv4. It matches every IPv4 destination, but it is used only when no more-specific route matches. A specific route therefore takes precedence over a default route.
End-to-end example: two subnets and one router
Consider this topology:
- Host A:
192.168.10.25/24 - Host A's default gateway:
192.168.10.1 - R1 interface GigabitEthernet0/0:
192.168.10.1/24 - R1 interface GigabitEthernet0/1:
192.168.20.1/24 - Host B:
192.168.20.50/24
- Host A compares its own subnet,
192.168.10.0/24, with Host B's subnet,192.168.20.0/24. - Because the subnets differ, Host A classifies Host B as remote.
- Host A sends the Ethernet frame to R1's local address,
192.168.10.1. The packet's destination IP remains192.168.20.50. - R1 receives the frame on
GigabitEthernet0/0and performs a lookup for192.168.20.50. - R1 finds a connected route for
192.168.20.0/24throughGigabitEthernet0/1. - R1 sends a new Layer 2 frame through
GigabitEthernet0/1, toward Host B's local address. - Host B receives the packet because
192.168.20.50is its own IP address.
Verifying routing on Cisco IOS
Display the routing table
show ip route
This command displays IPv4 routes, route codes, destination prefixes, next hops, metrics or administrative information, and outgoing interfaces. Use it to determine whether the router knows how to reach a destination network.
Check interface addresses and status
show ip interface brief
This command provides a quick view of interface IP addresses and operational states. A directly connected route depends on the corresponding interface being correctly addressed and active.
Configure a static route
ip route <destination-network> <subnet-mask> <next-hop-address-or-exit-interface>
For example, a route toward 172.16.20.0/24 through next hop 192.168.1.2 would follow this pattern:
ip route 172.16.20.0 255.255.255.0 192.168.1.2
Configure a static default route
ip route 0.0.0.0 0.0.0.0 <next-hop-address-or-exit-interface>
For example:
ip route 0.0.0.0 0.0.0.0 192.168.1.1
Troubleshooting IP routing
A host communicates locally but not with another subnet
- Verify the host IP address, prefix length, and default gateway.
- Confirm that the gateway address belongs to the host's local subnet.
- Check that the router interface on the local subnet is correctly addressed and operational.
Local communication working does not prove that the default gateway is correct. It only shows that local-subnet delivery is functioning.
The router receives packets but cannot reach the destination network
- Use
show ip routeto check whether a matching route exists. - Confirm that the destination prefix is correct.
- Verify the next hop is reachable and the outgoing interface is up.
- Check static routes for an incorrect destination mask, next hop, or interface.
Traffic uses an unexpected path
- List every route that could match the destination.
- Apply longest-prefix-match reasoning.
- Check whether a more-specific overlapping route exists.
- Determine whether the router is falling back to a default route because the intended specific route is missing.
- Review static and dynamically learned routes for incorrect prefixes or next hops.
Key points to remember
- IP routing forwards packets between separate IP networks.
- A host uses its IP address, subnet mask, and the destination IP address to decide whether traffic is local or remote.
- Remote traffic is sent to a default gateway reachable on the host's local subnet.
- A router examines the packet's destination IP address and looks it up in its routing table.
- The selected route identifies a next hop and/or outgoing interface.
- Layer 2 framing changes at each routed hop, while the destination IP drives the routing decision.
- The Cisco code
Cidentifies a directly connected route. - Static routes are manually configured; dynamic routes are learned through routing protocols.
- Longest-prefix matching selects the most specific matching route.
- A default route is a fallback used when no more-specific route matches.