The output is easily understood. The inetentry displays the IP address for the interface. UPsignifies that the interface is ready for use, BROADCASTdenotes that the interface is connected to a network that supports broadcast messaging ( ethernet), RUNNINGmeans that the interface is operating, and LOOPBACKshows which device ( lo) is the loopback address. The maximum transmission unit (MTU) on eth0is 1500 bytes. This determines the size of the largest packet that can be transmitted over this interface (and is sometimes "tuned" to other values for performance enhancement). Metricis a number from 0 to 3 that describes how much information from the interface is placed in the routing table. The lower the number, the smaller the amount of information.
The ifconfigcommand can be used to display information about or control a specific interface using commands as listed in Table 14.1. For example, to deactivate the first ethernet device on a host, use the ifconfigcommand, the interface name, and the command down, as follows:
# ifconfig eth0 down
You can also configure and activate the device by specifying a hostname or IP address and network information. For example, to configure and activate ("bring up") the eth0inter face with a specific IP address, use the ifconfigcommand like this:
# ifconfig eth0 192.168.0.9 netmask 255.255.255.0 up
If you have a host defined in your system's /etc/hostsfile (see the section "Network Configuration Files" later in this chapter), you can configure and activate the interface according to the defined hostname, like this:
# ifconfig eth0 dogdog.hudson.com up
Read the next section to see how to configure your system to work with your LAN.
/sbin/route
The second command used to configure your network is the route command. It is used to build the routing tables (in memory) implemented for routing packets as well as displaying the routing information. It is used after ifconfighas initialized the interface. The routecommand is normally used to set up static routes to other networks via the gateway or to other hosts. The command configuration is like this:
# route [ options ] [ commands ] [ parameters ]
To display the routing table, use the route command with no options. The display will look similar to this:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
149.112.50.64 * 255.255.255.192 U 0 0 0 eth0
208.59.243.0 * 255.255.255.0 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default 149.112.50.65 0.0.0.0 UG 0 0 0 eth0
In the first column, Destination is the IP address (or, if the host is in /etc/hostsor /etc/networks, the hostname) of the receiving host. The default entry is the default gateway for this machine. The Gatewaycolumn lists the gateway through which the packets must go to reach their destination. An asterisk ( *) means that packets go directly to the host. Genmaskis the netmask. The Flagscolumn can have several possible entries. In our example, Uverifies that the route is enabled and Gspecifies that Destinationrequires the use of a gateway. The Metriccolumn displays the distance to the Destination.Some daemons use this to figure the easiest route to the Destination.The Refcolumn is used by some UNIX flavors to convey the references to the route. It isn't used by Linux. The Usecolumn indicates the number of times this entry has been looked up. Finally, the Ifacecolumn is the name of the interface for the corresponding entry.
Using the -noption 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 routecommand can add to the table by using the addoption. With the addoption, you can specify a host ( -host) or a network ( -net) as the destination. If no option is used, the routecommand assumes that you are configuring the host issuing the command. The most common uses for the routecommand 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 ifconfigcommand to configure the interface. Assuming that the 208.59.243.0entry 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/routeto 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 routecommand 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 routecommand, 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 sockets (application-to-application connections between two computers). You can use netstatto 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/routecommand, the man page can give you details about all options and para meters.
Читать дальше