Network Computing   «Prev  Next»
Lesson 6Displaying routing tables
ObjectiveUse the Route Command to set your Default Gateway

Use Route Command to set your Default Gateway

When a computer needs to transmit information, it must determine the appropriate route. Usually, you send everything to the gateway to contact sites outside of your subnet, but some computers need more extensive routing information; for instance, if your gateway must route information between your subnet and other subnets, you need more detailed routing information.

Setting your default gateway

In practice, when you configure a network connection to an existing network, you use the route command to set the default gateway. For example, if your IP address was 195.77.4.3 and your subnet's gateway was set at 195.77.4.1, you might use route to set your interface's default route to point to the gateway; the MouseOver below explains each part of the route command line.

  1. add tells route what action to take
  2. default tells route to send all packets with unknown destinations to this interface
  3. gw means that you are going through a gateway and is followed by its IP address
  4. The last part of the line says that the gateway is on the same subnet as the device, eth0

Route Display Command
Red Hat Reference
Question: How do I setup default gateway with a route command?
Answer. route command show and/or manipulate the IP routing table under Linux and UNIX oses.
Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program. When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.

Display default route
Following three-command display the current routing table:
# route
Output:
Kernel IP routing table
Destination   Gateway      Genmask         Flags Metric Ref  Use Iface
192.168.1.0   *        		255.255.255.0   U     0      0    0   ra0
default       dsl-router   0.0.0.0         UG    0      0    0   ra0

Check default route

Check that the default route is set using the route −n command.
Destination, Gateway, Genmask, Flags, Metric

This shows that the gateway was set to the remote PPP server (198.62.1.1), as well as showing the other interfaces running on my computer. There are two ppp0 entries. The first shows the destination as a host (UH). The second shows the destination as a gateway (UG). All addresses that can’t be resolved on the local LAN are directed to the gateway address.

Check that the name servers are set

If you are able to ping a remote computer by IP address, but are not able to resolve any addresses, your DNS servers may not be set correctly. As root user from a Terminal window, open the /etc/resolv.conf file and check that there are lines identifying one or more DNS servers in this file. These should be supplied to you by your ISP. Here are some examples (the numbers are fictitious):
nameserver 111.11.11.111
nameserver 222.22.22.222

The next lesson shows you how to configure a modem to create a new PPP connection