View text source at Wikipedia
A default gateway is the node in a computer network using the Internet protocol suite that serves as the forwarding host (router) to other networks when no other route specification matches the destination IP address of a packet.
A gateway is a network node that serves as an access point to another network, often involving not only a change of addressing, but also a different networking technology. More narrowly defined, a router merely forwards packets between networks with different network prefixes. The networking software stack of each computer contains a routing table that specifies which interface is used for transmission and which router on the network is responsible for forwarding to a specific set of addresses. If none of these forwarding rules is appropriate for a given destination address, the default gateway is chosen as the router of last resort. The default gateway can be specified by the route command to configure the node's routing table and default route.
In a home or small office environment, the default gateway is a device, such as a DSL router or cable router, that connects the local network to the Internet. It serves as the default gateway for all network devices.
Enterprise network systems may require many internal network segments. A device wishing to communicate with a host on the public Internet, for example, forwards the packet to the default gateway for its network segment. This router also has a default route configured to a device on an adjacent network, one hop closer to the public network.
The following example shows IP addresses that might be used with an office network that consists of six hosts plus a router. The six hosts addresses are:
The router's inside address is:
The network has a subnet mask of:
The address range assignable to hosts is from 192.168.4.1 to 192.168.4.254. TCP/IP defines the addresses 192.168.4.0 (network ID address) and 192.168.4.255 (broadcast IP address).
The office's hosts send packets to addresses within this range directly, by resolving the destination IP address into a MAC address with the Address Resolution Protocol (ARP) sequence and then encapsulates the IP packet into a MAC frame addressed to the destination host.
A packet addressed outside of this range, for this example, addressed to 192.168.12.3, cannot travel directly to the destination. Instead it must be sent to the default gateway for further routing to their ultimate destination. In this example, the default gateway uses the IP address 192.168.4.1, which is resolved into a MAC address with ARP in the usual way. The destination IP address remains 192.168.12.3, but the next-hop MAC address is that of the gateway, rather than of the ultimate destination.
In another example, a network with three routers and three hosts is connected to the Internet through Router1. The hosts' addresses are:
Router1:
Router2:
Router3:
Network mask in all networks: 255.255.255.0 (/24 in CIDR notation). If the routers do not use a routing protocol to discover which network each router is connected to, then the routing table of each router must be set up.
Router1
Network ID | Network mask | Gateway | Interface (examples; may vary) | Cost (decreases the TTL) |
---|---|---|---|---|
0.0.0.0 (default route) | 0.0.0.0 | Assigned by ISP (e.g., 5.5.5.1) | eth0 (Ethernet 1st adapter) | 10 |
10.1.1.0 | 255.255.255.0 | 10.1.1.1 | eth1 (Ethernet 2nd adapter) | 10 |
172.16.1.0 | 255.255.255.0 | 10.1.1.2 | eth1 (Ethernet 2nd adapter) | 10 |
192.168.1.0 | 255.255.255.0 | 10.1.1.3 | eth1 (Ethernet 2nd adapter) | 10 |
Router2
Network ID | Network mask | Gateway | Interface (examples; may vary) | Cost (decreases the TTL) |
---|---|---|---|---|
0.0.0.0 (default route) | 0.0.0.0 | 10.1.1.1 | eth0 (Ethernet 1st adapter) | 10 |
172.16.1.0 | 255.255.255.0 | 172.16.1.1 | eth1 (Ethernet 2nd adapter) | 10 |
Router3
Network ID | Network mask | Gateway | Interface (examples; may vary) | Cost (decreases the TTL) |
---|---|---|---|---|
0.0.0.0 (default route) | 0.0.0.0 | 10.1.1.1 | eth0 (Ethernet 1st adapter) | 10 |
192.168.1.0 | 255.255.255.0 | 192.168.1.96 | eth1 (Ethernet 2nd adapter) | 10 |
Router2 manages its attached networks and default gateway; router 3 does the same; router 1 manages all routes within the internal networks.
Various utility software can show the default gateway. On Windows, ipconfig
may be used,[2] while on Unix systems, ifconfig
or netstat
may be used.[3] On Linux netstat
has been superseded by iproute2
.[4][5]