their destination. An asterisk (*
) means that packets go directly to the host. Genmask
is the netmask. The Flags
column can have several possible entries. In our example, U
verifies that the route is enabled and G
specifies that Destination
requires the use of a gateway. The Metric
column displays the distance to the Destination.
Some daemons use this to figure the easiest route to the Destination.
The Ref
column is used by some UNIX flavors to convey the references to the route. It isn't used by Linux. The Use
column indicates the number of times this entry has been looked up. Finally, the Iface
column is the name of the interface for the corresponding entry.
Using the -n
option to the route command gives the same information but substitutes IP addresses for any names and asterisks (*
) and looks like this:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
149.112.50.64 0.0.0.0 255.255.255.192 U 0 0 0 eth0
208.59.243.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 149.112.50.65 0.0.0.0 UG 0 0 0 eth0
The route
command can add to the table by using the add
option. With the add
option, you can specify a host (-host
) or a network (-net
) as the destination. If no option is used, the route
command assumes that you are configuring the host issuing the command. The most common uses for the route
command are to add the default gateway for a host, for a host that has lost its routing table, or if the gateway address has changed. For example, to add a gateway with a specific IP address, you could use the following:
# route add default gw 149.112.50.65
Note that you could use a hostname rather than an IP address if desired. Another common use is to add the network to the routing table right after using the ifconfig
command to configure the interface. Assuming that the 208.59.243.0
entry from the previous examples was missing, replace it using the following command:
# route add -net 208.59.243.0 netmask 255.255.255.0 dev eth0
You also can use /sbin/route
to configure a specific host for a direct (point-to-point) connection. For example, suppose that you have a home network of two computers. One of the computers has a modem through which it connects to your business network. You typically work at the other computer. You can use the route
command to establish a connection through specific hosts by using the following command:
# route add -host 198.135.62.25 gw 149.112.50.65
The preceding example makes the computer with the modem the gateway for the computer you are using. This type of command line is useful if you have a gateway or fire wall connected to the Internet. There are many additional uses for the route
command, such as manipulating the default packet size. See the man page for those uses.
/bin/netstat
The netstat command is used to display the status of your network. It has several para meters that can display as much or as little information as you prefer. The services are listed by netstat
to display the information in Table 14.2.
TABLE 14.2 netstat
Options
Option | Output |
---|---|
-g | Displays the multicast groups configured |
-i | Displays the interfaces configured by ifconfig |
-s | Lists a summary of activity for each protocol |
-v | Gives verbose output, listing both active and inactive sockets |
-c | Updates output every second (good for testing and troubleshooting) |
-e | Gives verbose output for active connections only |
-C | Displays information from the route cache and is good for looking at past connections |
Several other options are available for this command, but they are used less often. As with the /sbin/route
command, the man page can give you details about all options and para meters.
Network Configuration Files
As previously stated, seven network configuration files can be modified to make changes to basic network interaction of your system. The files are as follows:
> /etc/hosts
— A listing of addresses, hostnames, and aliases
> /etc/services
— Network service and port connections
> /etc/nsswitch.conf
— Linux network information service configuration
> /etc/resolv.conf
— Domain name service domain (search) settings
> /etc/host.conf
— Network information search order (by default, /etc/hosts
and then DNS)