'

Basic Networking Howto.

July 16th, 2008 by Andrea Matesi 963 Views

 

Since my job deals mainly with Networking stuff, I'm gonna post a summary for me, to remember always how does it works. The following takes into account the structure of LAN Networks with TCP/IP Suite of Protocols.

In the past, I (as many others), have fallen into confusion when talking about IP Addresses/Subnets-Subnet Mask, Broadcasts and Binary Conversion.

The following is my 2cents to help draw this confusion away.

Who invented IPv4 protocols, introduced the Classes concept to better separate and distinguish a Network from another.

Usually the difference between a class A, B or C address lies in the first 4 bits of the first octet.

Octet: a series of 8 bits composing an IP Address; this is an octet -> | 1 1 1 1 1 1 1 1 | wich translates as 255 on decimal, for us humans (try it with the calculator!)

A class A address does have the FIRST bit of the octet as a ZERO, so -> | 0 1 1 1 1 1 1 1 | translates to 127, but 127 class A address is reserved for loopback, so the range for Class A Network is 1..126 (126 is | 0 1 1 1 1 1 1 0 | ) (loopback is a special address that refer always to "YOUR_PC").

Class B address does have the SECOND bit of the octet as a ZERO, so -> | 1 0 0 0 0 0 0 0 | translates to 128, then the range assigned to class B is 128..191 (191 is | 1 0 1 1 1 1 1 1 | ).

Class C address does have the THIRD bit of the octet as a ZERO, so -> | 1 1 0 0 0 0 0 0 | translates to 192, then the range assigned to class B is 192..203 (203 is | 1 1 0 1 1 1 1 1 | ).

Class D is another form of Classes, intuitively Class D range from 224..239 (wich is | 1 1 1 0 0 0 0 0 | to | 1 1 1 0 1 1 1 1 |), where ZERO Lies on the fourth bit position.

After the preview, now let's analyze how subnetting works.

To understand subnetting, it is important to remember that, inside a Network, there are some constraints:

  1. A network has a well-defined IP address that have usually a zero (ex. 192.168.1.0) [but it can be different from zero just in case].
  2. A Network does have always a Broadcast address (usually in the form of network-address plus last bits set at 1, i.e.: 192.168.1.255).
  3. The Network is an address masked with a Subnet Mask (in fact a Network can also be called just a Subnet).
  4. There is a limited number of possible addresses (based on the Subnet mask).

It is almost impossible to make a huge single network (like a pure class B - 65536 hosts), without considering subnetting, because the network will become clogged, slow and unmaintainable (technically there happens "collisions"). The problem lies on broadcasting: when you have a huge segment, and a client broadcasts, this broadcast spread to the entire, 65536 hosts' network! So when you logically separate a network from the other, the broadcasts are limited to a subnet.

For this reason we use subnetting, by separating a Network Segment from another and by joining them accordingly by using a router, usually a device with two I/Fs, one on either end, connecting two different networks.

Enter Subnet Mask.

The Subnet Mask is an IP-like address composed of binary ONES and ZEROS. The SM is a layer applied to an IP Address to "identify" and distinguish a network from the hosts.

An IP address is composed of bits, these bits can be one or zeros; when you specify a mask, you have to apply this mask to the IP address to identify precisely what the network is.

Example:
IP: 192.168.1.0 - netmask: 255.255.255.0

Open questions:

  1. What is the class?
  2. What is the network?
  3. What is the Broadcast?
  4. What IP address the Network's hosts should have?

 Answers:

  1. The Class of the Network is Class C, because 192 translates to | 1 1 0 0 0 0 0 0 | and the ZERO lies on the third bit.
  2. The Network is 192.168.1.0, because the subnet mask is composed of all | 1 1 1 1 1 1 1 1 | on the first 3 octets, and when we have all 1s on the octet, we want to distinguish the network part from the host part [by assigning a 1 to the net and a 0 to the host]. This is how it works intuitively, in reality it is the result of a logical AND operation.
  3. The Broadcast address is 192.168.1.255, that is because all the host bits part should be set to all 1s, since the hosts part of the network is the 0 of the 192.168.1.0 network, and we set them to all 1s ( | 1 1 1 1 1 1 1 1 | -> 255 decimal).
  4. A host inside this network could have an address like 192.168.1.14 or 192.168.1.254 or whatever.

Extension of answer 3:
The logical AND operation gives 1 only when applied to two 1s, so:

0 AND 0 -> 0;

0 AND 1 -> 0;

1 AND 0 -> 0;

1 AND 1 -> 1;

If we put into column IP plus Subnet Mask, and we apply the AND operation on 'em, we'd obtain the right Network address:

IP: | 1 1 0 0 0 0 0 0 | . | 1 0 1 0 1 0 0 0 | . | 0 0 0 0 0 0 0 1 | . | 0 0 0 0 0 0 0 0 |

AND

M: | 1 1 1 1 1 1 1 1 | . | 1 1 1 1 1 1 1 1 | . | 1 1 1 1 1 1 1 1 | . | 0 0 0 0 0 0 0 0 |

we gain the right Network Address:

N: | 1 1 0 0 0 0 0 0 | . | 1 0 1 0 1 0 0 0 | . | 0 0 0 0 0 0 0 1 | . | 0 0 0 0 0 0 0 0 |

192.168.1.0

Addendum:

Today we can find some address expressed in the form IP.Address/number (like 192.168.1.0/24).

What this mean is simple: It is a network that dedicates the first 24 bits on the Subnet Mask (as 1s for the network part), and the rest 8 bits as 0s (on the hosts part). So we intuitively identify this network as 192.168.1.0 (given by the AND operation between the IP and the Subnet Mask,  192.168.1.0 AND 255.255.255.0 -> CONVERTED TO BINARY -> AND OPERATION -> CONVERT THE RESULT TO DECIMAL -> 192.168.1.0 as Network Address).

That seems all.

[UPDATE-2012-03-22]: Article revved and cleaned (some wrong information - maybe confusion brought me to write garbage, which is now fixed.).

[UPDATE-2012-03-22] BINARY TABLE:

128 64 32 16 8 4 2 1

This table is fundamental and allows you to convert ANY Decimal Number [up to 255] to binary.

Example: 221 TO BIN = ?

221 >= 128? 1

221 - 128 = 93.

93 >= 64? 1

93 - 64 = 29

29 >= 32? 0

29 >= 16? 1

29 - 16 = 13

13 >= 8? 1

13 - 8 = 5

5 >= 4? 1

5 - 4 = 1

1 >= 2? 0

1 >= 1? 1

221 to BIN = 1101 1101

Posted in Network Engineering | Comments Off on Basic Networking Howto.

Comments are closed.