Webmaster <(E-Mail Removed)> wrote:
> -Does this sound correct?
Almost, but what you call a "subnet", is really a "subnet mask".
Kernel IP routing table
Destination Gateway Genmask Flags Iface
202.89.56.1 0.0.0.0 255.255.255.255 UH ppp0
192.168.2.0 0.0.0.0 255.255.255.0 U eth1
10.18.0.0 0.0.0.0 255.255.0.0 U eth0
0.0.0.0 202.89.56.1 0.0.0.0 UG ppp0
Assume a packet comes into the router destined for 10.18.1.2. As a
simplified explanation (ignoring route cache), the packet will first be
AND'd with the first mask in the table (255.255.255.255). The result
is 10.18.1.2. This doesn't match the first destination 202.89.56.1,
so the route lookup code will go onto the next route entry.
Repeat using the next entry in the table.
10.18.1.2 && 255.255.255.0 = 10.18.1.0
192.168.2.0 != 10.18.1.0 so next route table entry.
10.18.1.2 && 255.255.0.0 = 10.18.0.0
10.18.0.0 == 10.18.0.0 (a match!)
The route entry that matched is
Destination Gateway Genmask Flags Iface
10.18.0.0 0.0.0.0 255.255.0.0 U eth0
There is no gateway associated with this route (no G in Flags), so it
get's sent out eth0 (the Iface)
Given the same routing table, a different packet destined for
123.123.12.3 would match the following route entry (which is the default
route, as anything ANDed with 0 is 0).
Destination Gateway Genmask Flags Iface
0.0.0.0 202.89.56.1 0.0.0.0 UG ppp0
Now, there is a G in the flags, so the packet goes out ppp0. The
destination address is unchanged. ppp0 is a Point-to-point link, so we
just need to throw it through the pipe, and it'll come out the other
end.
If the default route were to an ethernet, the IP address (as always)
will still be unchanged, but the layer 2 MAC address (destination
ethernet address) will be the MAC address of the gateway's interface on
that ethernet.
--
Cameron Kerr
(E-Mail Removed) :
http://nzgeeks.org/cameron/
Empowered by Perl!