Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Can someone explain how IP routing works to me?

E.g. if I ping, how does each router know which way to go as shown in a traceroute dump.

share|improve this question

closed as too broad by David Schwartz, kasperd, womble, Jenny D, Cristian Ciupitu Aug 25 at 16:30

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

You want someone to type out what has been explained many times? – d-_-b Apr 19 '10 at 4:42

2 Answers 2

up vote 11 down vote accepted

This explanation will be simplified let me know if you want more details. It's not completely accurate but it should give you a a good explanation.

It basically bubbles up. When you do ping x. If your computer doesn't have address x in it's routing table it goes to it's gateway (if you look at your routing table it will be the one that has destination default or then it will look at it's routing table to see if it has a route that matches this address or IP range if for example if it had as a route it would send it to what ever IP address it has associated with that route. If it doesn't it will do the same as your computer, send it to the default route.

For your computer for example, this will end when your ISP receives this and it will send it to what ever peer it knows has a route for this address (or is likely too, they share routing tables at that level). Then the reverse process happens, it goes down towards more specific ranges until it reaches the computer in question.

  1. your compter(no match, send to default route)
  2. your router (no match, send to default route) ->
  3. ....
  4. router X (match found for with associated address
  5. router at (match found for with associated address
  6. router at (match found for with associated address
  7. router at is directly connected to that computer(or thru a switch) and it sends it the packet because it knows it's network card mac address.

The commands route and traceroute (tracert for windows) might help make this clearer. On unix these commands have a -n option that make them show the address and not the DNS name of the particular address.

using route, my default route is show do be:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    100    0        0 eth0

the IFACE here is important because it tells the computer what network card is connected to this router which is at My computer will send all packets with unknown location through the eth0 network card.

share|improve this answer

Each router gets an IP packet with a destination address. It will pick a next hop, based on the most specific route that matches the destination.

If we start from your computer, it will have two (there may be more, but "two" is the typical case) routes installed. One is for the LAN it's on, the other is for ("the internet", usually called the default route). If the machine you ping is not local to the LAN, the packet will be sent to the default gateway.

Then, each intermediate router, until the router that has the destination LAN attached, will do the same thing. Look up the most specific route to the destination, then send teh packet on.

The intermediate routers will, most probably, have learned of the best route using one or more routing protocols (BGP, OSPF or similar), both to lessen the administrative burden and to provide a measure of fault tolerance.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.