All the hosts in IPv4 environment are assigned unique logical IP addresses. When a host wants to send some data to another host on the network, it needs the physical (MAC) address of the destination host. To get the MAC address, the host broadcasts ARP message and asks to give the MAC address whoever is the owner of destination IP address. All the host on that segment receives ARP packet but only the host which has its IP matching with the one in ARP message, replies with its MAC address. Once the sender receives the MAC address of receiving station, data is sent on the physical media.
In case, the IP does not belong to the local subnet. The data is sent to the destination by means of Gateway of the subnet. To understand the packet flow we must first understand following components:
MAC Address:
Media Access Control Address is 48-bit factory hard coded physical address of network device which can uniquely be identified. This address is assigned by device manufacturers.
Address Resolution Protocol:
Address Resolution Protocol is used to acquire the MAC address of a host whose IP address is known. ARP is a Broadcast packet which is received by all the host in the network segment. But only the host whose IP is mentioned in ARP responds to it providing its MAC address.
Proxy Server:
To access Internet, network uses Proxy Server which has a public IP assigned. All PCs request Proxy Server for a Server on Internet, Proxy Server on behalf of PC sends the request to server and when it receives response from the Server, the Proxy Server forwards it to the client PC. This is a way to control Internet access in computer networks and it helps to implement web based policies.
Dynamic Host Control Protocol:
DHCP is a service by which a host is assigned IP address from a pre-defined address pool. DHCP server also provides necessary information such as Gateway IP, DNS Server Address, lease assigned with the IP etc. By using DHCP services network administrator can manage assignment of IP addresses at ease.
Domain Name System:
This is very likely that a user does not know the IP address of a remote Server he wants to connect to. When the user types in the name of remote server he wants to connect to the localhost behind the screens sends a DNS query. Domain Name System is a method to acquire the IP address of the host whose Domain Name is known.
Network Address Translation:
Almost all PCs in a computer network are assigned private IP addresses which are not routable on Internet. As soon as a router receives an IP packet with private IP address it drops it. In order to access Servers on public private address, computer networks use an address translation service, which translates between public and private addresses, called Network Address Translation. When a PC sends an IP packet out of a private network, NAT changes the private IP address with public IP address and vice versa.
We can now describe the packet flow. Assume that a user wants to access www.gmail.com from her personal computer. She is having internet connection from her ISP. The following steps will be taken by the system to help her reach destination website.
Step: 1 – Acquiring an IP Address (DHCP)
When user’s PC boots up, it searches for a DHCP server to acquire an IP address. For the same, PC sends a DHCPDISCOVER broadcast which is received by one or more DHCP servers on the subnet and they all respond with DHCPOFFER which includes all the necessary details like IP, subnet, Gateway, DNS etc. PC sends DHCPREQUEST packet in order to request the offered IP address. Finally, DHCP sends DHCPACK packet to tell PC that it can keep the IP for some given amount of time aka IP lease.
Alternatively a PC can be assigned an IP address manually without taking any help from DHCP Server. When a PC is well configured with IP address details, it can now speak to other computers all over the IP enabled network.
Step: 2 – DNS query
When a user opens a web browser and types www.gmail.com which is a domain name and a PC does not understand how to communicate with the server using domain names. PC sends a DNS query out on the network in order to obtain the IP address pertaining to the domain name. The pre-configured DNS server responds the query with IP address of the domain name specified.
Step: 3 – ARP request
The PC finds that the destination IP address does not belong to his own IP address range and it has to forward the request to the Gateway. Gateway in this scenario can be a router or a Proxy Server. Though Gateway’s IP address is known to the client machine but computers do not exchange data on IP addresses rather they need machine’s hardware address which is Layer-2 factory coded MAC address. To obtain the MAC address of the Gateway the client PC broadcasts an ARP request saying "Who owns this IP address?" The Gateway in response to the ARP query sends it MAC address. Upon receiving MAC address PC sends the packets to Gateway.
An IP packet has both source and destination addresses and this connects host with a remote host logically. Whereas MAC addresses helps systems on a single network segment to transfer actual data. This is important that source and destination MAC addresses change as they travel across the Internet (segment by segment) but source and destination IP address never changes.