Выбрать главу

The ifconfig man page shows other options that enable your machine to interface with a number of network types such as AppleTalk, Novell, IPv6, and others. Again, read the man page for details on these network types.

NOTE

Promiscuous mode causes the NIC to receive all packets on the network. It is often used to sniff a network. Multicasting mode enables the NIC to receive all multicast traffic on the network.

If no argument is given, ifconfig displays the status of active interfaces. For example, the output of ifconfig, without arguments and one active and configured NIC, looks similar to this:

ifconfig

eth0 Link encap:Ethernet HWaddr 00:30:1B:0B:07:0D

     inet addr:192.168.0.7 Bcast:192.168.0.255 Mask:255.255.255.0

     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

     RX packets:127948 errors:0 dropped:0 overruns:0 frame:0

     TX packets:172675 errors:0 dropped:0 overruns:0 carrier:0

     collisions:7874 txqueuelen:100

     RX bytes:19098389 (14.2 Mb) TX bytes:73768657 (70.3 Mb)

     Interrupt:11 Base address:0x2000

lo   Link encap:Local Loopback

     inet addr:127.0.0.1 Mask:255.0.0.0

     UP LOOPBACK RUNNING MTU:16436 Metric:1

     RX packets:215214 errors:0 dropped:0 overruns:0 frame:0

     TX packets:215214 errors:0 dropped:0 overruns:0 carrier:0

     collisions:0 txqueuelen:0

     RX bytes:68739080 (65.5 Mb) TX bytes:68739080 (65.5 Mb)

The output is easily understood. The inet entry displays the IP address for the interface. UP signifies that the interface is ready for use, BROADCAST denotes that the interface is connected to a network that supports broadcast messaging (ethernet), RUNNING means that the interface is operating, and LOOPBACK shows which device (lo) is the loopback address. The maximum transmission unit (MTU) on eth0 is 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). Metric is 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 ifconfig command 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 ifconfig command, 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 eth0 inter face with a specific IP address, use the ifconfig command 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/hosts file (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 ifconfig has initialized the interface. The route command 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/hosts or /etc/networks, the hostname) of the receiving host. The default entry is the default gateway for this machine. The Gateway column lists the gateway through which the packets must go to reach 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: