Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

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 professional 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.

1  
Very Easy Answer. Go study subnetting and routing. This is 101 stuff and homework is off-topic for ServerFault. –  Magellan Oct 13 '12 at 15:32
    
Sometimes it helps to be pointed in the right direction, subnetting is a complex area to cover even for people who've 'done networking' for a long time. I still refer to cheatsheets... and occasionally have to go read serverfault. ;-) –  Christopher Woods Nov 5 '13 at 17:56

2 Answers 2

up vote 3 down vote accepted

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

route add 10.34.2.0 mask 255.255.255.0 10.34.1.1

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

route add 10.34.3.4 mask 255.255.255.255 10.34.1.2

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

route add 0.0.0.0 mask 0.0.0.0 10.34.1.3 metric 10
route add 0.0.0.0 mask 0.0.0.0 10.34.1.4 metric 5

10.34.1.4 would be the preferred route, assuming no other matching routes exist with a lower metric

share|improve this answer

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:

Class A
1.  0.  0.  1 = 00000000.00000000.00000000.00000000
127.255.255.254 = 01111111.11111111.11111111.11111111
                  0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHH

Class B
128.  1.  0.  1= 10000000.00000000.00000000.00000000
191.255.255.255 = 10111111.11111111.11111111.11111111
                  10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH

Class C
192.  0.  1.  1 = 11000000.00000000.00000000.00000000
223.255.255.254 = 11011111.11111111.11111111.11111111
                  110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH

Class D
224.  0.  0.  0 = 11100000.00000000.00000000.00000000
239.255.255.254 = 11101111.11111111.11111111.11111111
                  1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

Class E
240.  0.  0.  0 = 11110000.00000000.00000000.00000000
255.255.255.254 = 11111111.11111111.11111111.11111111
                  1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

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

route add 10.10.10.0 mask 255.0.0.0 192.168.1.1

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)

share|improve this answer
    
I work with programmable control station. When I want to communicate with another station in another subnet, I can only define a destination network and a gateway but no subnet mask. So I think the subnet mask is always set to 0.0.0.0. Commonly the destination network is set to 0.0.0.0 and only the gateway is defined. What now can happen is, that there are two gateways but both of this static routes has for destination network 0.0.0.0. This still works. But I can't exactly say why it works? –  reneton Sep 29 '12 at 9:29
    
are you sure it defines the subnet mask, maybe if doesn't use subnet mask (classful routing) or it puts default subnet mask for that network class. Do you have some sort of routing table that you could paste in your question, something like the route print command on windows, if you have multiple routes for same destination then the one with lower metric or cost or hops (whatever your station has defined in routing table) would win –  Alen Sep 29 '12 at 9:37
    
I don't know if the subnet mask is defined by the network class, I assume not. I configure the station with a GUI, in this GUI I can only define destination and gateway. When I look at the routing table on the station, I can't see a subnet mask for the destination network. –  reneton Sep 29 '12 at 10:00

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