When I define a static route, why I have to define a subnet mask for the destination network? What would happen, when I have more than one gateway an the subnet masks of all destination networks are 0.0.0.0?
closed as off topic by pauska, Magellan, John Gardeniers, mulaz, MadHatter Oct 15 '12 at 14:09
Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.
Because the destination network address by itself doesn't give a range of network addresses, however when coupled with a netmask, the full scope of the remote network is defined.
For example, say you were using a host on the network 10.34.1.0/24 and had a route defined as follows
The above rule, tells your computer that any host on the network 10.34.2.0/24 (10.34.2.1 - 10.34.2.254) is accessible via the router 10.34.1.1
Specifying a destination without a subnet mask doesn't make sense, even in the event of a single host, which would be defined as
If you have conflicting routes using a netmask of 0.0.0.0, then route with the lowest metric value would normally take precedence, for example
10.34.1.4 would be the preferred route, assuming no other matching routes exist with a lower metric
subnet mask serves to tell your router/OS what exactly is the network portion of your address.
Let's say you have 10.1.2.0 if you would have no network mask (this is called classful routing) if it's pressumed that it is 10.0.0.0 network because it belongs to Class A (some devices/OS give it the subnet defined on their interface). See here about classful and classless routing
These are the classes:
But if you put subnet mask then you can split that 10.0.0.0 network into more networks like 10.1.0.0 or 10.1.1.0.
The subnet mask is required because when you define static address (let's say in windows, it doesn't use calssful routing but classless, which has to have the subnet mask to).
If you put subnet mask of 255.0.0.0 that means that only the first part of the address is the network address so your network is x.0.0.0, if you would put 255.255.0.0 then it takes the first two part of the address like x.x.0.0, and so on. So when you put subnet mask 0.0.0.0 it means any address from 0.0.0.0 to 255.255.255.255.
If you have more than one route for same destination the route with lower metric will win.
About having subnet mask of your destinations set to 0.0.0.0 in most devices/OS I don't think it is possible to put subnet mask 0.0.0.0 if the address is not 0.0.0.0. That is they don't allow to put 1 bit value in destination address of static route if the corresponding value in subnet mask is 0.
Windows for instance won't let you make this
because you specified subnet mask of 255.0.0.0 which is in binary form 11111111.00000000.00000000.00000000 and the destination address 10.10.10.0 which is in binary form 00001010.00001010.00001010.00000000. It has 1 in the place where subnet mask has 0 (second and third portion of address)