The default route which is also known as the gateway of last resort is used in forwarding packets whose destination address does not match any route in the routing table. In IPv4 the CIDR notation for a default route is 0.0.0.0/0 and ::/0 in IPv6. Now since both the host/network portion and the prefix length is zero, a default route is the shortest possible match. In previous lessons in which we discussed basics of IP Routing, we know that a router when performing a route lookup will select a route with the longest possible match based on CIDR specifications, however, if the packet does not match any route in the routing table it will match a default route, the shortest possible route, if it exists in the routing table. A default route is very useful in a network where learning all the more specific routes is not desirable such as in case of stub networks. A default is immensely useful when a router is connected to the Internet as without a default route the router must have the routing entry for all networks on the Internet which are in numbers of several hundred thousand, however with single route configured as the default the router will only need to know the destinations internal to the administrative domain and will forward IP packets for any other address towards the Internet using the default route.
The default gateway is a device such as a router that serves as the edge devices providing an access point to other networks and is used to forward IP packets that do not match any routes in the routing table. We usually encounter the concept of default gateways in our daily computer life. The LAN configuration in our windows requires us to specify the IP address, Subnet Mask, and the Default Gateway to access the Internet. The default gateway IP address is the IP address of the CPE or Internet modems which provide the connectivity to the Internet, now since the Internet has several hundred thousand routes which we cannot install in our table, we simply tell our computer to forward all packets destined to the Internet to this device. Again the CPE will itself have a default route and gateway configured which will point to the ISP access device.
The figure below illustrates the concept of default routes and gateways.
Router R1 connects two internal networks of an organization and provides connectivity between them, it also connects to the Internet via an ISP CPE device to provide Internet access to the users. On R1 a default route is only needed to provide Internet connectivity which is configured as shown below.
Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1
All packets not matching a specific match in the routing table will be matched using the default route and forwarded to 192.168.1.2 which is the default gateway for R1. Similarly on every computer connected to either of the organization’s LAN will have the IP address of the router configured as the default gateway.
Now at the packet level what happens is that when a device attached to the network needs to communicate with another device it will first check whether the other device is on the same network or another network by comparing the IP address of the other device with subnet mask assigned to itself. If it is on another network then it will create a packet with the source IP of itself and destination of the other device. However, the layer 2 frame will have the source address of the device itself while the destination address will be the layer 2 address of the gateway. As the packet is routed by intermediate routers the packet will remain the same i.e no change in source and destination IP addresses while the layer 2 frame will change as it crosses networks i.e the source and destination mac addresses will be changed after every layer 3 hop.
This brings us to the end of this lesson in which we discussed the concept of default routes and default gateways. Both of these concepts are very essential as a network administrator you will encounter both of these in the daily job life.