LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-14-2010, 03:05 AM   #1
turiyain
Member
 
Registered: Dec 2006
Location: Delhi, India
Distribution: Centos 5.8, 6.5 Linux Mint 13 & 16, OpenSuse 12
Posts: 112

Rep: Reputation: 16
Subnet,Network IP, Broadcast IP Calculation


Dear Experts,

I am basically from system side and often confused about the calculation of the IP addresses.Just i want to know that what how can i calculate the following of a IP Address:

(1) Available IP in a Network
(2) Broadcast IP
(3) Network Prefix or Net Mask

Is there any way or technique to learn this easily.This is very urgent for me.

Very very thanks in advance.

Vijay Thakur
 
Old 02-14-2010, 04:34 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
The subnetwork entry in Wikipedia describes this in some detail.

Just a quick overview (ignoring IPv6 for simplicity, and assuming an understanding of binary numbers):

An IP address is a 32 bit number, represented for convenience as groups of 8 bits (in decimal rather than hex for some odd reason).

In a local network, the leading bits are the network prefix (ie, they identify the subnet), and the trailing bits are the host address (ie, they identify each computer on the subnet). The netmask is just an IP address in which the leading bits are all set to 1 (so it can be used to mask out the network prefix from the full IP address).

Since the trailing bits are the host address, that is what determines the number of available IP addresses in the subnet. That means if there are N host address bits, then there are 2^N-2 possible host addresses. The '-2' is because 2 of the addresses are reserved; one of the reserved addresses is the broadcast address, in which all host address bits are set to 1.

Take, for example, a typical local network IP address of 192.168.10.3. The binary representation of this is:
11000000 10101000 00001010 00000011

This is a typical class C address, meaning that the network prefix is probably the first 24 bits, ie
11000000 10101000 00001010
(which could also be written as 192.168.10.0/24)

And the network mask is just a bitmask that masks those first 24 bits, ie:
11111111 11111111 11111111 00000000
(also written as 255.255.255.0, or just /24)

The host address is the remaining 8 bits, ie:
00000011

Since there are 8 bits for the host address, this means there are 2^8-2 possible addresses, or 254 addresses, on the subnet. And the broadcast address for this subnet is where the host address bits are all on, ie:
11000000 10101000 00001010 11111111
(which can be written as 192.168.10.255)

Note that even though the parts of the address are broken up on an 8 bit boundary here, they can actually be broken at any point, as defined by the netmask.

Last edited by neonsignal; 02-14-2010 at 04:41 AM.
 
Old 02-14-2010, 07:42 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The NAG guide (Network Administrator's Guide) on the www.tldp.org website is a prior version of the same book you can find in the book store.
 
Old 02-14-2010, 08:05 AM   #4
devwatchdog
Member
 
Registered: Jan 2010
Posts: 202

Rep: Reputation: 47
This is a useful tool for calculating the information you need quickly:

Code:
jcwx@haley:~$ ipcalc 192.168.10.0 255.255.255.248
Address:   192.168.10.0         11000000.10101000.00001010.00000 000
Netmask:   255.255.255.248 = 29 11111111.11111111.11111111.11111 000
Wildcard:  0.0.0.7              00000000.00000000.00000000.00000 111
=>
Network:   192.168.10.0/29      11000000.10101000.00001010.00000 000
HostMin:   192.168.10.1         11000000.10101000.00001010.00000 001
HostMax:   192.168.10.6         11000000.10101000.00001010.00000 110
Broadcast: 192.168.10.7         11000000.10101000.00001010.00000 111
Hosts/Net: 6                     Class C, Private Internet
or:
Code:
jcwx@haley:~$ ipcalc 192.168.10.0/29
Address:   192.168.10.0         11000000.10101000.00001010.00000 000
Netmask:   255.255.255.248 = 29 11111111.11111111.11111111.11111 000
Wildcard:  0.0.0.7              00000000.00000000.00000000.00000 111
=>
Network:   192.168.10.0/29      11000000.10101000.00001010.00000 000
HostMin:   192.168.10.1         11000000.10101000.00001010.00000 001
HostMax:   192.168.10.6         11000000.10101000.00001010.00000 110
Broadcast: 192.168.10.7         11000000.10101000.00001010.00000 111
Hosts/Net: 6                     Class C, Private Internet

Last edited by devwatchdog; 02-14-2010 at 09:33 AM.
 
1 members found this post helpful.
Old 02-14-2010, 10:57 PM   #5
turiyain
Member
 
Registered: Dec 2006
Location: Delhi, India
Distribution: Centos 5.8, 6.5 Linux Mint 13 & 16, OpenSuse 12
Posts: 112

Original Poster
Rep: Reputation: 16
Cool

Thanks for your valuable answer. According to devwatchdog, i am using the ipcalc. But some time we are not in the position to access the computer e.g. meeting, conference, seminar or interview. In that situation, how can be calculate the subnet without using the paper and pen. Please guide me.
 
Old 02-15-2010, 01:47 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by turiyain View Post
I am basically from system side and often confused about the calculation of the IP addresses.Just i want to know that what how can i calculate the following of a IP Address:

(1) Available IP in a Network
(2) Broadcast IP
(3) Network Prefix or Net Mask

Is there any way or technique to learn this easily.This is very urgent for me.
I do not think this is possible because there is no way to look at an IP address and know how much of it is the network part.

As explained by neonsignal, a number (defined by the netmask) of leftmost binary digits in an IP address represent the network and the remaining bits identify:
the network (if all zeroes).
the broadcast address (if all ones).
a host (otherwise).


An example may help. The 10.x.x.x series may be class A address in which only the 10 identifies the network, the netmask would be 255.0.0.0, the network address would be 10.0.0.0 and the broadcast address would be 10.255.255.255. But it does not have to be used as a class A address, it may have any netmask applied, for example it may be netmasked into a class C address using netmask 255.255.255.0.

Now, what can you know about the netmask (and hence network address, broadast address and maximum possible number of hosts) from seeing 10.27.304.37?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ping broadcast doesn't yield reply from all alive hosts on my subnet?? rs_vijay Linux - Networking 3 07-06-2007 08:58 AM
udp broadcast from one subnet to another thru a linux router siva_bhavani Linux - Networking 1 12-30-2004 10:20 AM
Enabling subnet directed broadcast on Linux Router yrraja Linux - Networking 3 07-01-2004 12:27 PM
All network/broadcast pairs for subnet mask? debbo Linux - Networking 1 06-14-2004 04:27 PM
forward broadcast packets to another subnet VultureCulture Linux - Networking 9 10-25-2003 04:14 PM

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

All times are GMT -5. The time now is 11:54 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