-1

As I understand it IP 192.168.20.4/24 can only describe a host (24) on net 192.168.20.[1-254].

Now when describing a net; can 192.168.20.4/24 be a valid network ID, or should such a network ID always end with 0, as in 192.168.20.0/24, where 0 indicates that it is the network ID itself for net 192.168.20.[1-254]. So adding network:

sudo ip route add 192.168.20.4/24 dev eth0

is not allowed (which it also seems not to be).

I guess what I really want to know is, if something else than 0 is allowed when describing a network? When I look at routing table:

default via 172.18.0.1 dev eth0 
169.254.0.0/16 dev eth0  scope link  metric 1000 
172.18.0.0/24 dev eth0  proto kernel  scope link  src 172.18.0.150 
192.168.10.0/24 dev eth0  proto kernel  scope link  src 192.168.10.150

It kinda seems it could say (.7):

192.168.10.7/24 dev eth0  proto kernel  scope link  src 192.168.10.150

But that can never be right, correct? Instead it would have to say then (/32):

192.168.10.7/32 dev eth0  proto kernel  scope link  src 192.168.10.150

To describe the net consisting of only 1 single host(?). Have i understood things correctly?

JohnyTex
  • 101
  • 5

1 Answers1

3

There are more possibilities than zero for your network space. You could use .128 if you wanted to use the higher numbers in a /25, or .64 which will give you a range of .65-.126 with a broadcast of .127.

This works all the way up to 32. In the other direction /23, /22 and so on, it will always start with 0 because you will be using the entire 255 (and then some).

The idea is that it is the starting number on your network space, so if you want to use a /24, it will start at .0 If you're using a smaller space, you can start at zero, or at the beginning of any of the divisions.

There is a lot of information here, and on the internet in general about netmasks, it's worth spending a bit of time reading.

NickW
  • 10,263
  • 1
  • 20
  • 27
  • OK thx. Excellent answer! So 192.168.20.128/25 means network with hosts 192.168.20.[129-254], and 192.168.20.0/25 means network with hosts 192.168.20.[0-126]. But network 192.168.20.3/25 is not a valid network, correct? – JohnyTex Nov 17 '14 at 10:29
  • 1
    Correct, the divisors are always at the beginning of the space, otherwise, if you started at .3, you'd overlap the divisor, and do `.3-.131` which just doesn't work. – NickW Nov 17 '14 at 10:41
  • So 192.168.20.32/25 also doesn't work right? – JohnyTex Nov 17 '14 at 11:05
  • 1
    No, but `192.168.20.32/27` does. – NickW Nov 17 '14 at 11:20
  • So conclusion: the netmask "locks" the address space for the host. All the bits which aren't "locked" should be allowed to vary in any way they can, thus making up the host address space. The non-blocked all-zero address, is an identifier for the network itself. – JohnyTex Nov 17 '14 at 12:39
  • 1
    As a rule of thumb, yeah, but the actual reason is a bit more to do with math than I've said, have a look here: http://serverfault.com/questions/49765/how-does-ipv4-subnetting-work – NickW Nov 17 '14 at 12:42