# Routing Tables
## What is a Routing Table
A routing table is a database stored in a router or networked device that lists the routes to particular network destinations along with the metrics associated with those routes. When a router receives a packet, it examines the destination IP address and performs a lookup in its routing table to determine where to forward the packet. The routing table is the central data structure that enables routers to make forwarding decisions.
## Structure of a Routing Table Entry
Each entry in a routing table typically contains the destination network address and subnet mask or prefix length, the next-hop IP address or exit interface, a metric indicating the cost of the route, the source of the route such as directly connected, static, OSPF, or RIP, and an administrative distance value. The destination network is the network that the route applies to. The next-hop address is the IP address of the next router to which the packet should be forwarded. The exit interface is the local router interface through which the packet should be sent.
## Types of Routes
Directly connected routes are automatically added to the routing table when an interface is configured with an IP address and is active. These routes describe networks that are directly attached to the router's interfaces and have an administrative distance of zero. Static routes are manually configured by a network administrator. They do not change unless the administrator modifies them. Static routes are useful for small networks and for specific routing requirements. Dynamic routes are learned automatically through routing protocols. Routers exchange routing information with neighbors and update their tables based on the information received. Default routes specify where to send packets for destinations that do not match any more specific entry in the table.
## Longest Prefix Matching
When multiple routing table entries match the destination IP address of a packet, the router selects the entry with the longest matching prefix. This is called longest prefix matching or most specific route selection. For example, if the routing table has entries for 192.168.0.0/16 and 192.168.1.0/24, and the destination is 192.168.1.50, both entries match. The /24 entry is more specific and will be preferred. Longest prefix matching ensures that packets are forwarded using the most specific routing information available.
## Administrative Distance
When a router learns about the same destination from multiple sources, such as both OSPF and a static route, it uses administrative distance to select the preferred route. Lower administrative distance means higher trustworthiness. Directly connected routes have an administrative distance of 0. Static routes typically have an administrative distance of 1. OSPF has an administrative distance of 110. RIP has an administrative distance of 120. The route with the lowest administrative distance is installed in the routing table.
## Viewing Routing Tables
On Cisco routers, the command show ip route displays the routing table. Each line shows the source of the route indicated by a letter code, the destination network, the administrative distance and metric in brackets, and the next-hop address or exit interface. On Linux systems, the route command or ip route show command displays the routing table.Back to Subject