Calculating Subnets with "ipcalc"
Server Training - Server Administration

Calculating Subnets with "ipcalc"

Setting up a network can be fairly quick and easy if you're setting it up with straight Class A, Class B, or Class C network addresses. But, there may be occasions when you would only have a few hosts assigned to a given network segment. In that case, you wouldn't want to use a straight "classful " network addressing scheme, because you would waste too many IP addresses for that network. (You may need to use these IP addresses later if you decide to add other segments to your network.) This is where subnetting comes in handy.

When you subnet, you're dividing your Class A, Class B, or Class C network into two or more smaller networks. (These would be your "subnets".) But, when you subnet, you can't just assign host IP addresses willy-nilly. You'll need to perform some calculations in order to see which addresses go with each subnet. Once you get the hang of it, this is fairly easy to do with the old-fashioned pencil-and-paper method. The catch, though, is that it does sometimes take a while to get the hang of it. At first, it can be quite confusing. Besides, there are open-source tools available that can make the job go faster. One such tool is "ipcalc".

If you're running either Debian or some member of the Ubuntu family, you'll find ipcalc in the normal repositories. Just use either your favorite package manager or apt-get to install it.

Other distro's may or may not have ipcalc in their repositories. (We know for sure that it's not in the Vector Linux repositories, and that the ipcalc package that's in the RPMForge repositories for Red Hat-type distros is a different version that isn't very useful.) If your distro's repository doesn't have it, just download the archived file from the ipcalc website, and install it manually. It's a simple matter of unarchiving the file, changing to the resultant ipcalc directory, and invoking the ipcalc executable from the command-line. (Or, if you desire, move all of the files from the ipcalc directory to the /bin directory. That way, it'll be available for all users.)

ipcalc download site


So, how does this work?

Let's say that you've been assigned the address to work with. Your first subnet will only have 125 active hosts. To find out what your subnet configuration would be, invoke ipcalc with the -s option switch, along with the number of hosts that you need to accommodate.

First ipcalc example

You now have all of the information you need to set up your subnet, including the range of available IP addresses for your hosts, subnet mask, broadcast address, etc. You'll even see if there are any leftover subnets that haven't been used.

If you want to set up more than one subnet, enter the number of hosts you want on each subnet after a single -s switch.

Second ipcalc example

Oops, it looks like we made a slight error on this one. We tried to set up three 125-host subnets from our network. That doesn't work, since there are only enough host IP addresses to create two subnets.

For our next example, we've been assigned the network, and we need one subnet with two hosts, one with 45 hosts, and one with 125 hosts.

Third ipcalc example

Now, let's take a proposed subnet, and examine its information. All we have to do is invoke ipcalc along with the classful network address, and either the desired subnet mask or the number of bits in the desired mask.

Fourth ipcalc example

Next, we'll look at a proposed subnet setup with two different subnet masks. Since the output from this will be too long for our screen display, we'll redirect the output into a text file.

Fifth ipcalc example

And finally. . .

If you're working with someone else's computer, there may be times when you won't be able to install ipcalc. Not a problem. Just go to the ipcalc home page on use the on-line version.

ipcalc home page


That's all there is to it. Just a bit of practice, and you'll be subnetting with the pros!

Copyright CyberMontana Inc. and

All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874