When is the subnet mask used?

5

3

My NIC on my computer has a subnet mask. Is this only for it's own information? Or does the subnet mask get tossed into the TCP/IP headers to help the next device up route it? I'm guessing it's only for the individual device's information. Thanks for your replies in advance!

pkSML

Posted 2014-02-12T22:10:13.203

Reputation: 352

Answers

4

Neither IP or TCP include the subnet mask in their headers.

The subnet mask is used when receiving traffic - if traffic appears on the wire that is not within a subnet that the interface is assigned, it will drop it. If the interface is placed in promiscuous mode, then all traffic it receives is sent up the TCP/IP stack.

The OS uses the subnet mask to know if it should direct traffic directly to the destination IP (if it's within the subnet) or toward a (default) gateway (if it's not).

As NICs on the hardware level traditionally send and receive Ethernet frames, and not IP packets, I don't think this is necessarily a hardware function of the NIC - though modern NICs have "TCP Offload Engines" (TOEs) that perform much of the processing required by TCP on the NIC itself - those probably filter by subnet in hardware too.

LawrenceC

Posted 2014-02-12T22:10:13.203

Reputation: 63 487

if traffic appears on the wire that is not within a subnet that the interface is assigned what do you mean by wire? My computer is only connected by one wire to my router – CodyBugstein – 2015-02-24T12:32:55.083

It's possible - especially if you have multiple hosts connected by a hub and not a switch or an ancient bus-type network where all hosts are connected by the same physical wire - for a NIC to receive traffic that's not specifically destined for it (though rare). So your NIC can eavesdrop, and therefore can "hear" any traffic "on the wire." – LawrenceC – 2015-02-24T13:13:10.310

1Your answer is correct, but the last paragraph makes no sense. The router receives NO information in the TCP packet regarding the netmask (you said so yourself in the first line and that is correct). It also doesn't care about the target IP netmask. It just matches the target IP itself against it's routing tables to see which next-hop router it must be send to. And what has DHCP to do with this ? Routing tables are learned through a routing protocol or configured statically. Even if the router get's one of its own IP addresses through DHCP it contains no info about routing (except next-hop... – Tonny – 2014-02-12T22:34:43.467

... gateway for that interface). Baring any other information the router may use that next-hop gateway as "route of last resort". (This is the typical scenario for a customer-router connecting to an ISP. Infrastructure routers typically don't use DHCP at all.) – Tonny – 2014-02-12T22:37:20.993

Very true, once I read that again that didn't make a lot of sense. (I removed it.) I was thinking typical residential router where it gets its WAN IP from the upstream cable/DSL DHCP. – LawrenceC – 2014-02-12T22:43:34.327

Ah... Thanks @ultrasawblade and Tonny. I understand what you're saying perfectly. I think I'm going to go the library and get some networking books! Any recommendations would be appreciated. Thanks! – pkSML – 2014-02-13T02:16:23.547

1

The netmask, associated with a network interface, is used in the following situations:

  • Normally (but not necessarily) the routing system automatically creates a route to the subnet of the interface
  • IPv4 only: the host determines whether a packet received by an interface is a broadcast to own subnet (and should be processed as such).

These options are detailed in an article "Implications of Netmask Mismatch".

The netmask itself does not directly affect whether the host should send the packet directly to the destination address or to a gateway; it is the routing system which is responsible for this decision (but, as said above, netmasks are normally used for constructing the routing tables).

Konstantin Shemyak

Posted 2014-02-12T22:10:13.203

Reputation: 243