Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I understand that in internet routers route packet from source host to destination host by using its network address, as it is not possible to maintain route tables for each IP address.

My question is how does the router separate out the network address from an IP address? Does an IP packet contain the network address also? or does it contain which class(A/B/C/D) does the IP address belong to etc?

share|improve this question

3 Answers 3

99% of the time routers on the internet are only looking at the destination IP address when routing packets over the internet. They first inspect the packets destination IP address and then perform a lookup in their routing table, they are looking for the most specific route that matches that IP address.

Routes are considered more specific if they have a longer network mask, in this example consider the router has these two routes within the local routing table.

192.168.1.0/24 (255.255.255.0) via 10.0.0.1

192.168.1.1/32 (255.255.255.255) via 20.0.0.2

If we received a packet with a destination address of 192.168.1.1 we would use the more specific route (192.168.1.1/32), this is more specific because of the net-mask been the maximum length 32 bits long. Therefore the packet would be routed out of our interface providing connectivity to the next hop 20.0.0.2.

Where as a packet destined for 192.168.1.33 would use it's most specific route 192.168.1.0/24, this isn't the best possible route for that subnet, just the best route we have at the moment. This packet would be routed out of the interface providing connectivity to the next hop address of 10.0.0.1

Finally it's worth noting that routing tables are generally built on the internet using a dynamic routing protocol called BGP, this will go through a long process of determining the 'best' route to install within the routing table, even before packets start to route.

share|improve this answer

Classes don't really exist anymore. Modern routers have, for each route, a network number and a subnet length. The packet only contains the destination IP address. The router routes the packet using the matching route with the longest subnet length. (Sometimes called the "longest prefix" or "most specific" matching route.)

This is explained well on the Wikipedia Longest prefix match page.

share|improve this answer

Full explanation can be found at howstuffworks Franklin, Curt. "How Routers Work" 31 July 2000. HowStuffWorks.com..

Basically the router only needs to know whether a packet is local or remote. If it's local it delivers the package directly, if it's anything else it is delivered to another router the router itself is connected to and so on.

share|improve this answer
    
-1: it can't be that simple. Each router would need to be connected to at least two other routers, which begs the question, how do the routers decide which router to route a “remote” packet to? –  Blacklight Shining Oct 15 '13 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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