What are the effects of incorrectly setting the netmask?

10,274

Solution 1

While this question is probably more about IP networks than programming it is a challenging subject for many developers.

The netmask delimits the host address (your PC or server) and the network address (the part of the logical network infrastructure in which your system lives). The two parts are used to deliver the data packet to the correct device. The network address is obtained by ANDing the netmask with the IP Address. Consider the following scenario:

IP Address: 10.0.1.1
Netmask: 255.255.0.0

The host address portion of the IP address for our PC is 1.1, so the PC knows that any host addresses starting 10.0. are local to it. Any addresses that then start 10.1, etc, are not 'local' and will need to be forwarded to a router. If you have another device intended to be on the same network that is:

IP Address: 10.0.2.1
Netmask: 255.255.255.0

Here the netmask is wrong for our example setup, this device is now going to see the network address as 10.0.2 and the host address as 1, if it tries to communicate with 10.0.1.1 it will see a network address of 10.0.1! Not local and so will refer it to the default router for forwarding. If the netmask was correctly set (i.e. the same as the first example, assuming that's the correct setting for your network) then the second device would see the first as local, i.e. on the 10.0 network and wouldn't attempt to forward the packet to a router.

Many protocols will happily cope with this but tftp is intended to operate within a single network and so will fail as there's a perception that the target is on a different network.

This may not describe your exact situation but I hope that the example demonstrates the important principle that configuration matters, you can't have an inaccurately configured environment and expect it to work.

Solution 2

The netmask determines which IP adresses are local (non-routed); IP adresses outside that range go through the router. If the netmask is wrong, the program tries to directly access sites where it has to go through the router, or vice versa.

Solution 3

Possible implications of mismatched netmask are explained here. In short:

  1. The host is likely to construct routing table incorrectly.
  2. The host will miss some broadcast packets and not send broadcasts properly.

Mis-function of TFTP is almost for sure caused by the first reason. It affects any other IP protocol in the same way.

Other answers mention only the first problem (which is OK, as the second one is rather marginal). Note that it is not the netmask of the interface itself which determines how the IP packets would be routed - it is the routing subsystem of the host; but the netmask is normally used for constructing the routing table.

Share:
10,274

Related videos on Youtube

zooropa
Author by

zooropa

I am a Sr. Software Engineer working in the military simulation industry.

Updated on June 04, 2022

Comments

  • zooropa
    zooropa about 2 years

    What are the effects of incorrectly setting the netmask? I have a C++ application that sets the network mask of a device. If the netmask is set incorrectly, tftp doesn't seem to work properly. Why would this happen? What other problems occur when the netmask is not properly set for a device/PC?

    • zooropa
      zooropa over 14 years
      Whoever downvoted please leave comment for downvote. I would like to fix/explain whatever caused the downvote. Thanks.
    • jldupont
      jldupont over 14 years
      @zooropa: unfortunately, it is a common practice to have "drive-by down-votes" around here...
    • jcoder
      jcoder over 11 years
      Perhaps the downvote is due to the fact that this isn't really a programming question as such so could be considered off topic for this site. (I consider it close enough though, and it wasn't me!)
    • Kyle Strand
      Kyle Strand
      DIdn't downvote, but I removed the C/C++ tags, since this problem is not specific to those languages. Also, note that the downvote was removed sometime in the last 7 years (which may just mean that the user account was deleted). My suspicion is that the downvote was because the C and C++ tags rarely belong together, and the community on this site is fond of incessantly reminding people that they are completely different languages (sort of).