-->
Previous | Table of Contents | Next |
This causes ifconfig to activate Ethernet interface 0, look up the IP address for linux1 in the /etc/hosts file, and assign it to this interface. Examining the eth0 interface at this point reveals the following code:
$ ifconfig eth0 eth0 Link encap 10Mbps Ethernet HWaddr 00:00:E1:54:3B:82 inet addr 166.82.1.21Bcast166.82.1.255 Mask 255.255.255.0 UP BROADCAST RUNNING MTU 1500 Metric 0 RX packets 3136 errors 217 dropped 7 overrun 26 TX packets 1752 errors 25 dropped 0 overrun 0 Interrupt:10 Base address:0x300
Note that the broadcast address and netmask were set automatically by ifconfig based on the IP address it found in /etc/hosts. If youre using subnetworks, you need to specify the broadcast address and netmask explicitly. For example, if you have a class C network and are using the first bit in the host portion of the address to make two subnetworks, you must specify the broadcast address and netmask when running ifconfig :
ifconfig eth0 linux1 broadcast 166.82.1.127 netmask 255.255.255.128
The Parallel IP (PLIP), Serial Line IP (SLIP), and Point-to-Point Protocol (PPP) interfaces are managed by ifconfig somewhat differently. To bring up a PLIP interface, you add the pointopoint option to the ifconfig command line. Assume that the Burwell laptop linux2 is attached to the first parallel port on linux1. You call ifconfig as follows to activate the PLIP link:
ifconfig plip0 linux1 pointopoint linux2
This activates the plip0 interface with the IP address for linux1, sets the pointopoint flag, and tells the interface that the IP address for the other end of the link is linux2. ifconfig looks up the IP addresses for linux1 and linux2 in /etc/hosts and assigns the addresses appropriately. On a laptop, you use the analogous call
ifconfig plip0 linux2 pointopoint linux1
See See Understanding the Requirements for SLIP and PPP,p. 562
Routing determines the path a packet takes from its source through the network to its destination. This path is determined by matching the destination IP address against the kernel routing tables and transmitting the packet to the indicated machine, which may or may not be the destination of the packet. The kernel routing table contains information in the form To get to network X from machine Y, send the packet to machine Z with a cost of 1, along with time-to-live and reliability values for that route.
The first step in setting up routing on your network is deciding on a routing policy. For small, unconnected networks, using the route command to set up static routes on each machine at boot time is sufficient. Large networks with many subnets or networks connected to the Internet need to use dynamic routing. The routing program provides dynamic routing by communicating with routing programs on other machines and installing routes based on what it learns about the topology of the network.
A very common strategy combines static and dynamic routing. Machines on each subnet use static routing to reach their immediate neighbors. The default routethe route used for packets that match no other route in the routing tableis set to a gateway machine thats doing dynamic routing and knows about the rest of the world. Large networks can be constructed this way, minimizing the hassle of configuration files and the amount of bandwidth used by the dynamic routing programs.
The /sbin/route program manipulates the kernel routing table and is used to set static routes to other computers or networks via interfaces that have been configured and activated by ifconfig. This is normally done at boot time by the /etc/rc.d/rc3.d/S10network script. Table 24.3 describes the command-line arguments for /sbin/route.
Argument | Description |
---|---|
(None) | Giving no option to /sbin/route causes it to output the current routing table. |
-n | This argument causes the same output as giving no option, but replaces host names with their numerical IP addresses. |
del | This argument deletes the route for the specified destination address from the routing table. |
add | This argument adds to the routing table a route to the specified address or network. |
Examining the Kernel Routing Table
Running /sbin/route without any command-line arguments or just -n outputs the routing table:
/sbin/route Kernel routing table Destination Gateway Genmask Flags Metric Ref UseIface 127.0.0.0 * 255.0.0.0 U 0 0 100 lo
This is from a machine with just the loopback interface activated. Table 24.4 describes the fields in the routing table report.
Field | Description |
---|---|
Destination | The destination IP address of the route. |
Gateway | The host name or IP address of the gateway the route uses. If theres no gateway, an asterisk is output. |
Genmask | The netmask for the route. The kernel uses this to set the generality of a route by bitwise ANDing the Genmask against a packets IP address before comparing it to the destination IP address of the route. |
Flags | The flags for the route (U means up, H means host, G means gateway, D means dynamic route, and M means modified). |
Metric | The metric cost for the route. This isnt currently supported in the kernel networking layer. |
Ref | The number of other routes that rely on the presence of this route. |
Use | The number of times the routing table entry has been used. |
Iface | The network interface to which this route delivers packets. |
Previous | Table of Contents | Next |