From owner-freebsd-questions Sun May 2 18:17:32 1999 Delivered-To: freebsd-questions@freebsd.org Received: from bogslab.ucdavis.edu (bogslab.ucdavis.edu [169.237.68.34]) by hub.freebsd.org (Postfix) with ESMTP id 73F4215770 for ; Sun, 2 May 1999 18:17:30 -0700 (PDT) (envelope-from greg@bogslab.ucdavis.edu) Received: from deal1.bogs.org (deal1.bogs.org [198.137.203.51]) by bogslab.ucdavis.edu (8.9.3/8.9.3) with ESMTP id SAA11648 for ; Sun, 2 May 1999 18:17:25 -0700 (PDT) Received: from deal1.bogs.org (LOCALHOST [127.0.0.1]) by deal1.bogs.org (8.8.8/8.6.12) with ESMTP id SAA16692 for ; Sun, 2 May 1999 18:17:23 -0700 (PDT) Message-Id: <199905030117.SAA16692@deal1.bogs.org> To: questions@freebsd.org Subject: variable-sized subnets in class C Reply-To: gkshenaut@ucdavis.edu Date: Sun, 02 May 1999 18:17:23 -0700 From: Greg Shenaut Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I am trying to divide up my class C network into variably sized subnets. I think I understand how to do this, but I thought I'd write up what I think to be the constraints, and see if anyone more knowledgeable than I could keep me from making a mistake. The rules are: the highest and lowest address in each network cannot appear in a subnet. Always subnet in powers of two. When assigning host IPs within a subnet, the lowest subnet address (all zeros) is reserved for "this host", and the highest subnet address (all ones) is reserved for the subnet broadcast address. Smallest useful subnet is size 4; largest useful subnet is size 64. This is because if you have two subnets of size 128, they will both be invalid because of containing the lowest or highest network address; also, subnets cannot be of size two, because both addresses would then be reserved ("this host" or subnet broadcast). The lsbs of subnet masks are equal to 256-s, where s is the total number of addresses in the subnet (and from this it follows that the 0 bits in the subnet mask will always be contiguous & on the right). Also, by convention the highest usable address in a subnet is given to the default gateway for the subnet, if there is one. These are the largest legal subnets possible in an 8-bit class C network: 0-3 -- 4 unusable addresses 4-7 -- 4 addresses (max 2 usable) 8-15 -- 8 addresses (max 6 usable) 16-31 -- 16 addresses (max 14 usable) 32-63 -- 32 addresses (max 30 usable) 64-127 -- 64 addresses (max 62 usable) 128-191 -- 64 addresses (max 62 usable) 192-223 -- 32 addresses (max 30 usable) 224-239 -- 16 addresses (max 14 usable) 240-247 -- 8 addresses (max 6 usable) 248-251 -- 4 addresses (max 2 usable) 252-255 -- 4 unusable addresses All legal subnets can be subdivided recursively: 8 --> 4 + 4 16 --> 8 + 8 32 --> 16 + 16 64 --> 32 + 32 So for example, the range 32-63 could either have 14 valid IPs with a subnet mask of .224, or be subdivided into two ranges, 32-47 and 48-63, with subnet masks of .240. Each of these ranges could either have 6 valid IPs, or could be subdivided again into two subnets with netmasks of .224, each with 2 valid IPs. So the 16-address range can have the following possible subnet configurations: 1 14-host .224 subnet 2 6-host .240 subnets 1 6-host .240 subnet + 2 2-host .252 subnets 2 2-host .252 subnets + 1 6-host .240 subnets 4 2-host .252 subnets The other subnets of size 8-64 can be subdivided according to the same logic. What you can't do, though, is to combine any addresses across binary tree boundaries. For example, you cannot have * 1 10-host .??? subnet + 1 2-host .252 subnet * 1 2-host .252 subnet + 1 6-host .??? subnet + 1 2-host .252 subnet If you want, for example, to combine the two 64-address subnets and one 32-address subnet to give one subnet with 160 addresses, what you have to do is to set up the separate 64-address and 32-address subnets and route between them, for example by putting three ethernet cards in a FreeBSD machine, one connected to each subnet, and having it do the routing. Well, if anyone spots a flaw in this, please let me know. -Greg Shenaut To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message