2 Answers
2

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 0.0.0.0) 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 123.123.123.0/24 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.

your compter(no match, send to default route)

your router (no match, send to default route) ->

....

router X (match found for 123.0.0.0/8 with associated address 10.10.10.1)

router at 10.10.10.1 (match found for 123.123.0.0/16 with associated address 123.123.0.1)

router at 123.123.0.1 (match found for 123.123.123.0/24 with associated address 123.123.123.1)

router at 123.123.123.1 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.

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

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 0.0.0.0/0 ("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.