1

Answer provides the procedure to find the network address when a packet with destination IP(198.51.100.223/21) is reached at a router.

But a network packet has the destination IP 198.51.100.223 in the IP packet but does not include /21. Router looks up the table of network prefixes with subnet mask(for ex: 198.51.96.0/21).


Given a packet with destination IP(198.51.100.223) receiving at a router, How does a router determine its network address? to route the packet accordingly...

Ron Maupin
  • 99,565
  • 26
  • 120
  • 195
overexchange
  • 113
  • 5

1 Answers1

1

IP packets only have addresses, not masks or networks. An IPv4 address is simply a 32-bit number.

Routers have routing tables that consist of networks. A router will look for a routing table entry (network) that most closely matches the destination address of the IP address on the packet. If no possible match is found, the packet is discarded. If multiple matches are found, the longest match (most matched bits of the address and network) is used.

Some routers have default routes with the 0.0.0.0/0 network. Every IPv4 network is a subnet of that network, so if there are no other (longer) matches, that route will be used, preventing any packets from being discarded.

A router will take the destination IP address, and it will compare it to the routing table entries for the mask length number of bits. If every bit of the destination address for the length of the routing table mask matches the routing table entry, then the router has a match.

Ron Maupin
  • 99,565
  • 26
  • 120
  • 195
  • Does router use the subnet mask of each network prefix and then perform the AND operation on received packet destination IP? – overexchange Jan 10 '19 at 15:33
  • Yes. That is how you determine the network of the address. The router looks to see if the destination address is in the network of any routing table entry, and the entry with the longest match wins. – Ron Maupin Jan 10 '19 at 15:37
  • So... every table entry is (network_prefix_CIDR, next_hop_link), so router will forward the packet to next hop... Is that correct? – overexchange Jan 10 '19 at 15:38
  • Right. More advanced routers can do this in hardware using something like TCAM to greatly speed up the routing process over a software router. – Ron Maupin Jan 10 '19 at 15:41
  • @overexchange, TCAM is a form of CAM that can use a mask. See this question for a better explanation of CAM and TCAM. – Ron Maupin Jan 10 '19 at 15:43
  • And the routers go through learning of routing tables with intra-domain routing protocols like(Distance-Vector algo or Link-State algo or ...) Just trying to connect things. – overexchange Jan 10 '19 at 16:07
  • Routing protocols do not route; they are used to populate routing tables. Each routing protocol will have its own tables, and the router will take the best routes from the routing protocol tables to populate the routing table. If there is an identical route in multiple routing protocols, then something like AD (Administrative Distance) is used to select which routing protocol is most "trustworthy," and that routing protocol entry will be used in the routing table. – Ron Maupin Jan 10 '19 at 16:11