Display Your IP Routing Table


route

When you try to use Secure Shell (SSH) to connect to another computer on your LAN (something you'll learn about in Chapter 15, "Working on the Network"), how does your computer know that it should confine the packets to your LAN and not send them to your router to be sent out on the Internet? And if you point your web browser to www.ubuntu.com, how does your Linux box know to send that request to your router and not to another machine next to you?

The answer is that your Linux kernel has a routing table that keeps track of those things. To view your current routing table, simply enter route in your shell (no, you don't have to be root to view the routing table, but you do have to be root to change it, as you'll see in the next section).

$ route Kernel IP routing table Destination Gateway     Genmask       Flags Metric  Ref       Use Iface 192.168.0.0 *           255.255.255.0 U     0       0         0 eth0 default     192.168.0.1 0.0.0.0       UG    0       0         0 eth0 


Note

There's only one network interface on this machine, so this is a pretty simple routing table. On a laptop that has both an Ethernet port and a wireless card, you'll see additional entries.


An IP address is composed of four octets, giving it the appearance of xxx.xxx.xxx.xxx, as in 192.168.0.124. When you send a packet out of your machine, the IP address that is the destination of that packet is compared to the Destination column in the routing table. The Genmask column works with the Destination column to indicate which of the four octets should be examined to determine the packet's destination.

For example, let's say you enter ping 192.168.0.124 in your shell. A Genmask of 255.255.255.0 indicates that only the last octetthe number represented by 0matters. In other words, when looking at 192.168.0.124, only the .124 is important to route packets to that address. Any packets intended for 192.168.0.1 through 192.168.0.255 (the limits of an IP address) match the Genmask and the Destination, so they stay on the Local Area Network and avoid the router. That's why there's an * in the Gateway column next to 192.168.0.0: No Gateway is needed because that traffic is local.

On the other hand, everything else is by default intended for the router, which in this instance is at 192.168.0.1 in the Gateway column. The Genmask in this row is 0.0.0.0, indicating that any IP address not matching 192.168.0.1 through 192.168.0.255 should be sent through 192.168.0.1 (because 192.168.0.1 is the Gateway, it's a special case). 72.14.203.99, 82.211.81.166, and 216.23.180.5 all match with 0.0.0.0, so they must all go through the Gateway for the Net.

The other interesting thing about the routing table exposed by route is the Flags column, which gives information about the route. There are several possible flags, but the most common are U (the route is up) and G (use the gateway). In the preceding table, you can see that both routes are up, but only the second is the Gateway.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net