LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2009, 12:42 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
manually determining ip address ranges


Hi there --

I am trying to remember the procedure used to determine the ip address range when given a network address and its subnet mask. Does anyone have any documentation on the steps that are done to accomplish this? Thanks.
 
Old 09-08-2009, 12:48 PM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Do you want a subnet calculator or the actual steps to calculate it by hand?
 
Old 09-08-2009, 12:48 PM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

Have a look at these:

Wikipedia Subnetting
Ralphb.

Kind regards,

Eric
 
Old 09-08-2009, 01:00 PM   #4
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Hi there --

I am looking for the actual steps to calculate it by hand.

Thanks.
 
Old 09-08-2009, 01:33 PM   #5
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Haven't done that manually for ages, I'm ashamed to say. But after some Googling found this page that breaks it down so even I can understand it (and suddenly remember parts).

It explains it in detail.

Networking Basics

Kind regards,

Eric
 
Old 09-08-2009, 05:38 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
The howtos cited explain it pretty well. If I have a 'net connection I just use: http://www.subnet-calculator.com/cidr.php

If I have to calculate it manually for some reason (very rare), here's what I do...

Part 1

Keep in mind the following:
Code:
 2(7) | 2(6) | 2(5) | 2(4) | 2(3) | 2(2) | 2(1) | 2(0)
-------------------------------------------------------
 128  | 64   | 32   | 16   | 8    | 4    | 2    | 1
The top row is 2 (to the power of n) in each column. e.g.: 2 * 2 * 2 * 2 * 2 * 2 * 2 == 128

If you don't follow that part, then read it again and figure it out. The rest of this won't make sense until you get that much.

Part 2

Next, look at each netmask octet and convert it from decimal to binary.

Given the netmask 255.255.224.0:
  • 255 == 11111111
  • 255 == 11111111
  • 224 == 11100000
  • 0 == 00000000

So the netmask 255.255.255.224.0 in binary would be 11111111.11111111.11100000.00000000.

Understand so far? If not, re-read until you do, or the rest won't make sense.

Part 3

Remember that handy little chart from Part 1? We're going to use the bottom row of it here to take a different look at our binary netmask.

First octet:
Code:
 128  | 64   | 32   | 16   | 8    | 4    | 2    | 1
-------------------------------------------------------
 1      1      1      1      1      1      1      1
Second octet:
Code:
 128  | 64   | 32   | 16   | 8    | 4    | 2    | 1
-------------------------------------------------------
 1      1      1      1      1      1      1      1
Third octet (this is where it starts to get interesting):
Code:
 128  | 64   | 32   | 16   | 8    | 4    | 2    | 1
-------------------------------------------------------
 1      1      1      0      0      0      0      0
Fourth octet:
Code:
 128  | 64   | 32   | 16   | 8    | 4    | 2    | 1
-------------------------------------------------------
 0      0      0      0      0      0      0      0
Notice how the last column containing a '1' is third octet, 32 column? This means that our netmask breaks down IP networks into ranges of addresses 32 each. Thus, given the IP address 10.50.120.1/255.255.224.0, the ranges will look like:
  • 10.50.0.0 - 10.50.31.255
  • 10.50.32.0 - 10.50.63.255
  • 10.50.64.0 - 10.50.95.255
  • 10.50.96.0 - 10.50.127.255
  • 10.50.128.0 - 10.50.159.255
  • 10.50.160.0 - 10.50.191.255
  • 10.50.192.0 - 10.50.223.255
  • 10.50.224.0 - 10.50.255.0

Within that set of ranges, 10.50.120.1 is of course in 10.50.96.0 - 10.50.127.255. Note that the first and last addresses within a range may not actually be assigned to hosts. (The first is often the default router, and the last is usually the broadcast address.)

Free tip: Note that you can count (from left to right) the number of 1 values in your binary netmask to determine your CIDR notation netmask.

11111111 11111111 11100000 00000000 ... that's nineteen 1s, so your CIDR notation netmask is /19.

Your turn

Work through some examples on your own to make the process stick. Now that you know how to do it... you probably never will need to.

Aren't you glad you asked?
 
Old 09-08-2009, 06:00 PM   #7
baldy3105
Member
 
Registered: Jan 2003
Location: Cambridgeshire, UK
Distribution: Mint (Desktop), Debian (Server)
Posts: 891

Rep: Reputation: 184Reputation: 184
I do it like this -

256 - mask = number of hosts in network 256/number of hosts = number of networks.

So 255.255.255.128 gives you 256 - 128 = 128 hosts, 256/128 = 2 networks. So you have 2 networks with 128 hosts each.
(Remember you always lose the first and last host.)

For 255.255.255.224 , 256 - 224 = 32 hosts, 256 / 32 = 8 networks, so 8 networks of 32 hosts each.

Obviously for 255.255.240.0 you can do the same thing. 256 - 240 = 16, 256 / 16 = 16, however in this case you have 16 possible subnets of 255.255.0.0 each with 16 lots of 256 addresses.

For 255.192.0.0 you get 256 - 192 = 64, 256 / 64 = 4 so this is 4 subnets of 255.0.0.0 of 64(lots of 65536 addresses)

Or you can memorise this table -

128 = 2 x 128
192 = 4 x 64
224 = 8 x 32
240 = 16 x 16
248 = 32 x 8
252 = 64 x 4

Its not that hard and impresses your boss when you can do it in your head.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the load address of kernel module tommy24 Programming 2 08-03-2009 01:27 AM
Linux: Determining MAC address from C Mad_C Programming 9 02-11-2005 04:27 AM
Blocking IP Address ranges in dhcpd.conf pmcdaid Linux - Networking 4 06-09-2004 09:18 AM
network address ranges WeNdeL Linux - Networking 4 03-12-2003 10:56 AM
determining ppp ip address using perl Smerk Linux - Software 4 01-17-2003 07:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration