2

How does a router that receives a packet know what to do if it doesn’t know the subnet mask of the IP that sent the packet? The reason for asking this is that I didn't see any field in the IP header for a subnet mask. Does the router make the decision by doing a bitwise AND between the source IP and the subnet mask associated with the IP of the interface that received the packet?

Is it possible that at the exit of traffic from the ISP network there is only one router that contains a single summarized route? Or are there usually multiple routers at the ISP exit each having multiple routes?

Thank you

1
  • 1
    The router routes by the destination address, not the source address.
    – Ron Maupin
    Commented Feb 1 at 17:15

2 Answers 2

1

A router uses its routing table to make routing decisions. A packet's destination IP address is matched against the table and the next hop from the entry with the longest prefix match is used. The source IP address is irrelevant for forwarding.

I didn't see any field in the IP header for a subnet mask.

The subnet mask is not a property of an IP address but of a subnet. The router has subnet masks = prefix lengths on each of its routing table entries. Subnets that the router doesn't know about are irrelevant for making the routing decision.

Technically, the router applies a bitwise AND operation to the destination IP address and each of the routing table entries' network mask. If the result matches the (already masked) prefix the entry is chosen and the packet is forwarded to the indicated gateway.

Comparisons run from longest to shortest prefix, either iteratively with software-based routing, or in parallel using a ternary CAM (TCAM) for hardware-based routing.

Is it possible that at the exit of traffic from the ISP network there is only one router that contains a single summarized route? Or are there usually multiple routers at the ISP exit each having multiple routes?

A small ISP might just have a single uplink and default route. Larger ISPs peer with multiple other ISPs or carriers. They exchange routing information using BGP. Large ISPs or carriers commonly use no default route at all but rely on their peer information exclusively.

0

The one who makes the bitwise AND operation with the destination IP address and the subnet mask of the source IP prefix is the source (host) itself. The host does this to determine whether to send the packet directly to the LAN host or to the default gateway.

As @Zac67 pointed out, routers usually forward packets based on destination IP address - unless some policy based routing is used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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