Recently I've been having fun interconnecting multiple private networks at both work and private locations. I wanted a method to deterministically assign static IP addresses and subnets without too much worry of overlap for when DHCP doesn't work. Below is what I've come up with for myself.
Calculating an Octet
To come up with the octet (0-255) decide on the text string describing that octet, normalize the name (lowercase it and remove any spaces) and then calculate the CRC32 of that string as an unsigned integer. That gives me a large number which I then divide by 256 and use the remainder (mod
) as the octet.
For example: a private network located at '123 Any Street' would get the third octet of 15.
- '123 Any Street' is normalized to '123anystreet'
- CRC32 of '123anystreet' is 2973677327
- The remainder of 2973677327 divided by 256 is: 2973677327 mod 256 = 15
- Therefor the private network at 123 Any Street would be 192.168.15.0/24
For most private networks I'd let DHCP allocate the fourth octet and be done with it.
VPN Network Names
But for P2P VPN between hosts, like N2N
, an address doesn't make sense as the key to naming the network and running a DHCP server might not make sense in such decentralized manner. In that case I'd repeat the steps above with a descriptive name such as company name or department name and a descriptive host name such as 'sandy-macbook' as the strings to CRC32.
Hope that is helpful. You can likely find commercial products that take care of much of this for you but I'm cheap and I enjoy the details.