In the previous section, you saw how to manually configure an Ethernet network interface with a particular address and mask. You can connect to networks outside your subnet by adding a default gateway to your kernel's IP routing table with this command:
route add default gw gw-address
The gw-address parameter is the IP address of your default gateway; it must be an address in a locally connected subnet defined by the address and mask settings of your network interface (as described in the previous section). If you have a static IP address, a default route setting usually goes along with an ifconfig command in your boot sequence. For other kinds of connections, other programs usually set the default route.
To view the current default route, run this command:
The output should look something like this:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 10.1.2.1 0.0.0.0 UG 0 0 0 eth0
The ifconfig command that configured the eth0 network interface in this example added the first route line. However, the last line is the default gateway, because it has a netmask of 0.0.0.0, which allows the host to reach all other hosts on the Internet. The gateway's IP address is 10.1.2.1, and you can see that you reach that gateway through the eth0 network interface.
If you mistype a gateway address when adding a route, you cannot attach another gateway until you delete the erroneous entry. To remove the current default gateway, run this command:
route del -net default
Figure 5-1 on the next page shows a typical local area network with a gateway, or router. The subnet is 10.1.2.0/255.255.255.0 with a default gateway of 10.1.2.1. Each IP address represents a network interface, as does the uplink IP on the gateway. If you do not run the gateway, you do not need to worry about its uplink ” for example, if you are configuring a host with an IP address of 10.1.2.4, you need only know that 10.1.2.1 is the local IP address on the gateway.
If your netmask is 255.255.255.0, your router is probably at node 1 of the subnet (for example, 10.1.2.1 in 10.1.2.0/255.255.255.0). This is convention, not necessarily reality.
A properly configured default gateway allows you to connect to the rest of the world. However, you still need to know how to convert common names , or hostnames, to IP addresses.