IPv4


IPv4 in detail
As we already know an IPv4 uses 32 bit address as shown below.
8     8    8     8
X . X . X . X
The whole thing (ie, X.X.X.X) is called the network address. This is known as "dotted decimal" notation. Each ‘X’ is called an octet and all the four octets added together makes a 32bit address (IPv4 address). A valid IPv4 address will always be between;
0.0.0.0  to  255.255.255.255
Here 0.0.0.0 is called an ‘Invalid IP’ and 255.255.255.255 is called a ‘Global Broadcast IP address’. They both are not used in communication purposes.
As mentioned before each octet 'X' has 8 bits, which is show below; 
        
        22224   2221   20
        X . X . X . X . X . X . X . X
        0   0   0   0    0   0   0   0 = 0
        0   0   0   0    0   0   0   1 = 1
        0   0   0   0    0   0   1   0 = 2
        0   0   0   0    0   0   1   1 = 3
             .
             .
             .
        1   1   1   1    1   1   1   1 = 255

IP address Classes -
IANA (Internet Assigned Numbering Authority) has classified IP into the following classes;
Class A , Class B , Class C , Class D and Class E,
out of which Class A,B & C are used for the purpose of communication, Class D is used for multicast purpose and Class E is used in IP research.

Class A = 1 to 126
Class B = 128 to 191
Class C = 192 to 223
Class D = 224 to 239
Class E = 240 to 255


Inorder to find which Class a network address belongs to you need to look only at the value in the first octet of the network address. Examples;
172.16.62.36 is a Class B address because the first octet value 172 falls under Class B.
10.121.130.47 is a Class A address as the first octet value 10 falls under Class A.
192.168.12.31 is a Class C address as the first octet value 192 falls under Class C.

Addresses beginning with 127 decimal, are reserved for loopback and for internal testing on a local machine; [You can test this: you should always be able to ping 127.0.0.1, which points to yourself] (PING stands for Packet Internet Grapher)
Another IP address 169.254.0.0 to 169.254.255.255 is called a APIPA (Automatic Private IP Addressing)

APIPA is a feature of Microsoft Windows. With APIPA, DHCP clients can obtain IP addresses when DHCP servers are nonfunctional. APIPA exists in all popular versions of Windows except Windows NT. When a DHCP server fails, APIPA allocates addresses in the private range 169.254.0.1 to 169.254.255.254. Clients verify their address is unique on the LAN using ARP. When the DHCP server is again able to service requests, clients update their addresses automatically. In APIPA, all devices use the default network mask 255.255.0.0 and all reside on the same subnet. Example; Because APIPA uses IP addresses in the private Class B space, APIPA is a feature generally only useful on home or other small intranet LANs. (Note: You will be mainly doing this during the lab exercise in your classroom) 

Setting an IP address on your system -

1) Double click on Network Connections on your Desktop.
2)Network Connections window will appear. Right click correct Local Area    Connection by identifying correct network card and click Properties.
3)Select Internet Protocol (TCP/IP). Click on Properties.


Here, You can now key in the IP address, Subnet mask, Default gateway and DNS servers. If by default you already see an IP address on the screen you can change it by just switching between "Obtain an IP address automatically" and "Use the following IP address". This will leave the boxes blank.
Note: IP address of your computer must be unique. None of the 2 computers in the network can share same IP address, it causes IP address conflict. Default gateway is a router that can route the traffic to the other network or Internet. DNS server is an application server that can translate URL to IP address. As an example, www.cert.org is URL and it can be translated to 192.88.209.6 by DNS server.


If you have DHCP server setup on your router or you have DHCP server in home network, your computer can be assigned IP address automatically by selecting Obtain an IP address automatically and Obtain DNS server address automatically.

If you have a notebook, using static IP at home and the IP assigned by DHCP server at the office, you can make use of Alternate Configuration to set IP and network information for these 2 different network. Set Obtain an IP address automatically on General tab which is same as what I specified above, so that the notebook will be assigned IP addresses automatically at the office. After that, click Alternate Configuration tab, select User configured option and key in your home network’s static IP information. By setting this, when there is no IP information assigned due to no DHCP server at home, this alternate configuration will be applied automatically, so that you don’t have to set IP manually every time at home. 
 

DHCP (Dynamic Host Configuration Protocol) is a communication  protocol that lets network administrators centrally manage and automate the assignment of Internet Protocol (IP) addresses in an organization's network. 
How does it work?
Say there are two or more servers. Now a client machines wants an IP address for networking.
1- The client machine will broadcast (one to all) a DHCP-DiscoverPacket asking "Who can give me DHCP information?
2- Now the servers on the subnet  unicast (one to one) a DHCP-OfferPacket saying "I can supply you with the DHCP information, if you like?" 
3- The client machine will select one of the response and will broadcast DHCP-RequestPacket saying "I choose Server ABC, Server ABC this is my MAC address, what is my IP address?" The unchosen servers will treat this broadcast as a rejection. The client may also specify any additional information if required. 
4- The server will then respond with a DHCP-AcknowledgmentPacket saying "Here's you IP address." The server will also record the information that the particular IP address is in use by the client machine. The response from the server may also contain additional information if requested by the client.

DNS is a protocol within the set of standards for how computers exchange data on the Internet and on many private networks. Its basic job is to turn a user-friendly domain name like "google.com" into an Internet Protocol (IP) address like 209.85.148.106 that computers use to identify each other on the network. DNS server resolves the domain name to the IP address. For example, when you enter "http://www.google.com" in your browser, part of the network connection includes resolving the domain name "google.com" into an IP address, 209.85.148.106, for google Web servers. You can always bypass a DNS lookup by entering 209.85.148.106 directly in your browser, that is if you know the IP address.
Note: Box (1), the url is http://www.google.com
Box (2), the domain name is www.google.com, and in
Box (3) the IP address is 209.85.148.106

Before a packet can be sent across a physical network, the IP software must translate the IP address of the destination host into an equivalent hardware address. This process is known as address resolution. The protocol used for this purpose is called Address Resolution Protocol (ARP). One host can resolve the address of another host only if both hosts are attached to the same physical network - a host never resolves the address of a host on another network.

Network Portion & Host Portion of classes
In a Class C the first three octets are assigned as ‘Network Portions’ and the last octet is assigned as a ‘Host Portion’.
N
N
N
H
 Class C

For other classes the Network and Host portions are likewise;

N
N
H
H
Class B


N
H
H
H
Class A

Two PC’s can only communicate with each other if their Network Portions of their network address match. For example; consider a PC1 with a network address 192.168.1.11 and PC2 with a network address 192.168.2.10 (both are Class C addresses as the first octet value is 192). These PC’s will not be able to communicate, as their Network Portions do not match.

Network address & Broadcast address
Consider the example, 140.179.220.200, which is a Class B address. In order to specify the network address for a given IP address, the host section is set to all '0's. In our example, 140.179.0.0 specifies the network address or parent address for 140.179.220.200. When the host section is set to all '1's, it specifies a broadcast that is sent to all hosts on the network. 140.179.255.255 specifies the example broadcast address.

Private & Public IP address (or Subnets)
There are three IP network addresses reserved for private networks. The addresses are;
10.0.0.0 to 10.255.255.255, Subnet Mask 255.0.0.0 (Class A)
172.16.0.0 to 172.31.255.255, Subnet Mask 255.240.0.0 (Class B) and
192.168.0.0 to 192.168.255.255, Subnet Mask 255.255.0.0 (Class C)
They can be used by anyone setting up internal IP networks, such as a lab or home LAN behind a NAT or proxy server or a router.


Subnet Mask
Applying a subnet mask to an IP address allows you to identify the network and host parts of the address. The network bits are represented by the ‘1’ in the mask, and the host bits are represented by the ‘0’. Performing a bitwise logical AND operation between the IP address and the subnet mask results in the Network Address or Number.
For example, using our test IP address and the default Class B subnet mask, we get: 

How to find the Subnet Mask on a PC?

(1) Go to Start Menu -> Run 
        Type cmd and press enter to open the command prompt window.

              Now type ipconfig /all  

(2) Open Network Connections from the desktop and double click the Local Area Network icon. Then just click on the support tab at the top of the window

Note:
Linux/ Unix – On Linux or Unix system just type following commands on shell to get the subnet mask.
$ ifconfig
or
$ /sbin/ifconfig


Default Gateway (DG)
 A gateway is a device or software in the network. It is the exit interface to go from one network to another. Gateway is responsible for connecting physically two different networks. A gateway can connect a Local Area Network to a Wide Area Network or a    Virtual Private Network over the internet or it can be also used to connect to the internet itself. As described earlier that a Gateway is all the times directly connected to the internet well then it is directly exposed to the security threats which comes from the internet so a Gateway should be properly configured and secured and the in and out traffic should be monitored. If you are using a DSL connection that you will need a DSL modem which comes with the built-in function. The telephone line is connected with the DSL modem and UTP/STP cable attaches your computer with the DSL modem. Modems are the devices that are used to modulate and demodulate the data. They convert analogue signals to digital and digital signals to analogue so that signals can travel on the telephone lines. 
Fig- Broadband Router
Fig- Internet Connection using Broadband Router
In Broadband Router there is a device called NAT (Network Address Translation) which enables the communication between a Private and Public.
Note: In normal circumstance communication is only possible between Private and Private; Public and Public. Communication is not possible between a Private and Public. However, by using a Broadband Router which uses NAT technology this has become possible.

Fig- Cable Modem
Fig- Internet connection using a Cable modem
 In the figure above you can only connect one system to the internet. If you want to connect multiple systems to the internet, then you need to add another NIC to the PC and by using a Switch you will be able to connect multiple systems. See figure below;

Fig- Internet connection using a Cable modem but with two NIC's
A IP address will be assigned to NIC2, which becomes the Default Gateway for the system.