Calculate PREFIX from subnet mask in bootscripts
spyro at f2s.com
Tue Oct 19 08:42:57 PDT 2004
Gerard Beekmans wrote:
> So never mind my question about what 255.255.255.252 is. It's /30
> according to this table. Good enough for me. Though I'd still appreciate
> the math behind it if anybody can explain it.
Yeah its dead easy.
the subnet mask divides the ip into network and host addresses
if you AND the mask with the ip you get the network address (sorta)
if you and the inverse of the mask with the IP you get the host address
on that network.
so, taking each digit in turn
nm: 255.255.255.248 (this is a /29)
this is, in binary:
so, ANDing the ip and nm give us a network addr:
although really we discard the non network bits, leaving:
and a host number of:
More information about the lfs-dev