0

I am wondering what is the netmask used for in the Linux network stack.

Let's assume I have an interface eth0 configured to ip 1.1.1.1 and netmask 255.255.255.0

now I am sending a packet to 1.1.1.2 and a packet to 1.2.3.4. Why does my linux machine need to be aware of the network architecture to service these two request?

I would expect that in both cases an arp request will be sent, and for the first the real host will answer and for the second the qualifying router will answer.

2 Answers 2

2

I would expect that in both cases an arp request will be sent, and for the first the real host will answer and for the second the qualifying router will answer.

No, the router only provides an ARP response if the ARP request is for the IP-addresses of one of the router's own interfaces.

The client uses the netmask to decide if the destination IP is LAN-local or needs to be routed.

If the client determines that the destination is outside the LAN, it selects an appropriate router from its routing table. Often this will be a "default gateway" configured statically or, more likely nowadays, by DHCP, at startup.

The client would then broadcast an ARP request to find the MAC-address for the router's IP address, after receiving the arp response it can then send packets to the router that have the router's MAC address and the final destination's IP-address. The client also stashes the router's MAC address and IP-address in its ARP-cache to save having to do further ARP requests fro the same info.

0
0

Your local machine has an ARP cache. This is the table of ARP responses for each IP address. You don't want 4 billion entries in this cache. The netmask tells you which addresses should be cached.

That said, the qualifying router (gateway) will also have a local address, because it must be reachable. (You can explicitly configure this as well). So that packets to 1.2.3.4 will actually trigger an ARP request for the configured gateway address (say 1.1.1.254). As it's a router, 1.1.1.254 won't be surprised when it gets a packet for 1.2.3.4.

1
  • I hate downvoting so I will not do this to you, but this answer is truly wrong, and RedGrittyBrick's is correct: the netmask is used to distinguish which IP addresses are directly reachable (i.e., they belong to the same physical segment and thus need no gateway) from the IP addresses which do require crossing one or more gateways which then need routing. Nothing to do with an ARP cache (though that comes in handy, of course). Aug 2, 2016 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .