« Home | Where do the IP addresses come from? » | Just what is routing? » | Mysql Database Backup Script » | Listing files by size » | Where am i always » | Possible to get the administrator password ? » | 11 Unix Tricks » | Who sent me mail » | Strings - old but a goodie » | Run daily with at » 

Friday, March 17, 2006 

Revealing your routing tables

From a command line on any Linux system, you can see the existing routing table by simply typing 'route' at the prompt. (Type '/sbin/route' if /sbin is not in your path.) Your routing table will be similar to this:
# route
destination gateway interface
63.63.63.0 * eth0
default 63.63.63.6 eth

Advanced routing commands are issued as arguments to the 'ip' command. To see the routing table with iproute2, you can use the long version "ip route show table main" or the shortcut version "ip route" like this:

# ip route
63.63.63.0/29 dev eth0 proto kernel scope link src 63.63.63.1
default via 63.63.63.6 dev eth0

Recall that in our simple example, all ip addresses are considered to be either 'local' or 'not local'. For this network, a local address will be in the range from 63.63.63.1 to 63.63.63.6. A non-local address is just anything else.* It's traditional to assign the router the highest address in the range (ending in 6 for this network).

The first line in the routing table says that if the address is local, your computer puts the packet right out onto the ethernet wire using interface /dev/eth0. The only other device on your local network right now is the DSL router at 63.63.63.6. You can probably use a browser to bring up the router's built-in web-based configuration interface by connecting to http://63.63.63.6/

When you want to surf over to linuxforums.org, the packets need to go to the Internet. You computer will use DNS to translate the name linuxforums.org into its IP address (67.15.52.42). Your computer sees that address is not local, so it uses teh 'default' entry in the routing table and sends the packet to your DSL router.

In turn, the DSL router looks at the destination address, and sees that the data is destined for somewhere on the Internet. The DSL router then pushes the packet out its DSL connection to the next router upstream which is at your ISP. Just as with the postcard analogy, it's now out of your hands; more upstream routers send it on its way to the linuxforums.org server.

When the response comes back from linuxforums.org, there is a destination address of 63.63.63.1 in the packet, so when it hits your DSL router it will pass the packet onto your LAN. Your desktop computer sees the packet on the LAN and picks it up. The round trip connection is now completed. It takes many such exchanges of packets to pass all the data required for just a single page.

If you have a web server running on your local computer, everything works pretty much the same way, but the traffic flows the other direction. Requests for pages come in from the Internet and your web server responds by sending pages back out via the DSL router. Usually you arrange to get your ip address into a DNS server somewhere so that you can publish a URL for your server with a friendly name like "http://myveryownserver.org" but you could just as easily not bother with that and just tell all your friends that your URL is http://63.63.63.1/.

When a friend surfs to http://63.63.63.1/, your web server will receive the request with a source address pointing back to your friend's computer. Thus the reply will be routed back out via your one and only default router.

* Yes, I know there is another internal network on the address 127.0.0.1. It's called the loopback interface /dev/lo. But let's not worry about it here, okay?

Links to this post

Create a Link

About me

  • I'm Adrian
  • From Manila, Philippines
  • Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange.
My profile

Links

    Add to Google Add Mox Diamond to Newsburst from CNET News.com Subscribe in NewsGator Online Subscribe in FeedLounge Add to netvibes
Powered by Blogger
and Blogger Templates