Charles <(E-Mail Removed)> wrote:
>I am trying to understand what this means...
>
>[charles@host ~]$ /sbin/route -n
>Kernel IP routing table
>Destination Gateway Genmask Flags Metric Ref Use
>Iface
>192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0
>eth0
>169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0
>eth0
>0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0
>eth0
>[charles@host ~]$
>
>The first number, 192.168.1.0, is not a real address. So how can it be
>a destination for anything.
The /ifconfig/ command deals with setting or printing the
network interface configuration for *receiving* data packets.
It deals with the IP addresses for network interfaces, not the
IP addresses in data packets. As such it has no effect on
outgoing packets. Incoming packets depend on the IP assigned by
/ifconfig/ to know which interface is the right one.
The /route/ command deals with setting or printing the
configuration for *sending* data packets. It deals with the IP
addresses in packets, not those of the network interfaces. As
such it has no effect on incoming packets. Outgoing packets
depend on the routes assigned by /route/ to know which interface
is the right one.
So when we look at a route table, do not expect to see anything
to do with the IP addresses of your host. In fact, the only
actual IP address you'll see is that of a gateway, and then only
on a route that says we not only send it to a specific network
interface, but we send it to an IP address that it is not
addressed to.
So... all of those entries in the route table are basically
*subnetting*, because you have multiple networks and it is
necessary to decide on a per packet basis which network gets
which packets. There are three basic fields used to decide
that, and if they match, that line is what determines the
routing. If they don't match, the next line is examined.
The process used is to take the packet's destination address,
mask it with the "Genmask" field, and then compare that to the
"Destination" field. If they compare true, that line selects
the interface to use.
Hence, the first line of your route table, which looked like
this (with some editing to delete fields we are ignoring),
Destination Gateway Genmask ... Iface
192.168.1.0 0.0.0.0 255.255.255.0 eth0
If we send a packet to address 192.168.2.20, when masked with 255.255.255.0
we get 192.168.2.0, which does *not* match the Destination field, 192.168.1.0,
so that line does not determine where the packet is sent.
If the next line looked like this,
192.168.2.0 0.0.0.0 255.255.255.0 eth1
The IP packet addressed to 192.168.2.20, when masked, does match
the Destinations field, and that packet would go to interface
eth1.
Now, consider sending a packet to 127.1.2.3 (something you will want to
try, just to verify that this works). Not shown in your route table, but
no doubt actually there, is a line like this
127.0.0.0 0.0.0.0 255.0.0.0 lo
So if we mask 127.1.2.3 with 255.0.0.0, we get 127.0.0.0 which
matches the destination field and the packet goes to the lo
interface. The point being that while "localhost" is assigned
127.0.0.1 and that is commonly used as a loopback, the route
table is actually set up so that you have thousands of IP
addresses that are a loopback. Any address with 127.x.x.x will
be sent to the lo interface.
Some ethernet configuration tools use the address 169.254.0.0 as
a bogus route for an unconfigured network, and hence that shows
up and is confusing.
If the "Destination" or the "Genmask" fields have 0.0.0.0, the result
is a mask/compare operation which will yield true for any address, and
hence it provides a default for any otherwise unrouted packet.
The same 0.0.0.0 is a bogus address when placed into the Gateway
field as an indication that no gateway exists. A gateway is
necessary when the packet is addressed to an IP address not
available on a directly connected network. The packet is sent
to a host that is on a connected network, which necessarily must
be able to forward the message to either addressed host or to
another gateway.
The above tells you how to read a route table, but it doesn't explain
how to set routes in the table. Setting routes is worth an entire
post all by itself, so I'll not bore you with it unless you ask.
--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)
(E-Mail Removed)