Ethical Hacking Training Institute
Extreme Hacking | Sadik Shaikh | Cyber Suraksha Abhiyan
In this tutorial, we will cover some networking basics. We won’t be hacking anything, but by the end of the tutorial you’ll learn a lot of things which will be useful later, especially when you’ll use nmap. Please note that it is advised that you go through wikipedia pages of all the concepts covered here since the discussion won’t be exhaustive in any way.
IP address
Decimal notation – 192.168.1.1
Binary – 11000000.10101000.00000001.00000001
It is clear from the binary form that the IP is indeed 32 bits. It can range from 0.0.0.0 to 255.255.255.255 (for the binary all 0s and all 1s respectively) [A lot of time, the first octet usually goes upto 127 only. However, we aren’t concerned with that here.]
Parts of an IP address
Need for Netmasks
Netmask
We’ll start with a basic example. Suppose we want to define a netmask which configures our network like wireless router in the previous example. We want the first 3 octets to correspond to the network and next 1 octet for host address.
Let’s think of an operation which we can use to separate the network and host part of the IP address. For simple purposes, we could have just defined after which octet does the host part start [basically saying that anything after the third period(.) is host address]. While this is a simple solution, it is not very versatile.
A more elegant and mathematical solution was proposed.
Netmask – Working
First I’ll tell you the mathematical functionality of a netmask. Assume A to be an IP address and M to be a netmask. Then,
A & M gives the Network address
A & (~M) gives the Host address.
Where,
& is bitwise And
~ is bitwise Not (i.e. complement, 1s complement to be more precise)
So, basically a netmask is another 32 bit binary number (just like an IP address), but with the purpose of giving Host address and network address when the operation bitwise and is carried out on it (and it’s complement) with A.
Example
You’ll understand better with example.
A = 192.168.1.1 is you IP address
M = 255.255.255.0
We convert it to binary, and then carry out the desired operations.
A = 11000000.10101000.00000001.00000001 (192.168.1.1)
M = 11111111.11111111.11111111.00000000 (255.255.255.0)
A&M = 11000000.10101000.00000001.00000000 (192.168.1.0)
A&M is network IP that we desired
A = 11000000.10101000.00000001.00000001 (192.168.1.1)
~M = 00000000.00000000.00000000.11111111 (0.0.0.255)
A&~M= 00000000.00000000.00000000.00000001 (0.0.0.1)
A&~M is host IP that we desired
Explanation
Basically, if you realize that 11111111 is 255 in decimal, then you can see that for the parts of the IP address that you want for networks, you set the subnet to 255, and for the ones you want for host, you set it to 0.
So, if you want to reserve 2 octets for networks and 2 for hosts, then the subnet will be-
M = 255.255.0.0
If you want 3 octets for host, then
M = 255.0.0.0
Hence, we can see that using netmasks we can achieve what we wanted, i.e. to define networks with whatever number of hosts we require. Now we go a bit further.
Subnets
Now suppose you want to divide your network into parts. It is the sub-networks that are known as subnets (it is correct to call them subnetwork as well).
We’ll jump right to it, consider the netmask M
M = 11111111.11111111.11111111.11000000
Now, the first 3 octets describe the network. But the 4th octet, which is supposed to be for the host, has the 2 most significant bits (i.e. leftmost bits) as 1. Thus, the 2 most significant (leftmost) bits of the 4th octet will show up when we carry out the bitwise AND operation. They will, thus, be a part of the network address. However, they belong to the host octet. Thus, these 2 bits, which belong to the host octet but show up in the network IP address divide the network into subnets. The 2 bits can represent 4 possible combinations, 00, 01, 10 and 11, and hence the network will have 4 subnets.
Example of Subnetwork
Back to our previous “A”,
A = 11000000.10101000.00000001.xx000001 (192.168.1.1)
M = 11111111.11111111.11111111.11000000 (255.255.255.192)
A&M = 11000000.10101000.00000001.xx000000 (192.168.1.0)
Earlier, irrespective of what was there in 4th octet of A, we would have got all 0s in 4th octet of A&M i.e. network address. This time we will get the 2 most significant bits in the network address. Four subnets will be formed depending on the value of xx (which can be 00,01,10 or 11). Now, we will see which subnet has which set of hosts.
Which subnet has which hosts
11000000.10101000.00000001.00000000
has hosts 192.168.1.0-63 (00000000 to 00111111)
11000000.10101000.00000001.01000000
has hosts 192.168.1.64-127 (01000000 to 01111111)
11000000.10101000.00000001.10000000
has host 192.168.1.128-191 (10000000 to 10111111)
11000000.10101000.00000001.11000000
has host 192.168.1.192-255 (11000000 to 11111111)
So the netmask M divided the network into 4 equal subnets with 64 hosts each. There are some subnets which are much more complicated and have their applications in certain specific areas. I recommend going through Wikipedia page on Subnetworks to get some more idea. I have covered enough and now you can understand Wikipedia;s content on the topic without any difficulty.
Some Special IPs
Finally
Sadik Shaikh | Cyber Suraksha Abhiyan, Ethical Hacking Training Institute, CEHv9,CHFI,ECSAv9,CAST,ENSA, CCNA, CCNA SECURITY,MCITP,RHCE,CHECKPOINT, ASA FIREWALL,VMWARE,CLOUD,ANDROID,IPHONE,NETWORKING HARDWARE,TRAINING INSTITUTE IN PUNE, Certified Ethical Hacking,Center For Advanced Security Training in India, ceh v9 course in Pune-India, ceh certification in pune-India, ceh v9 training in Pune-India, Ethical Hacking Course in Pune-India