In this above scenario, while we ping HostB from HostA the ARP packet goes all the way from host A to host B in order to find the MAC of hostB. At the very first time ARP packet goes out from RouterA(Gateway for HostA) the source address is changed from HostA's address to RouterA's adress. Once MAC table is formed, The dest IP of ARP or ICMP is not changed. What is the reason behind that?... Thanks in Advance
Your statement ""In this above scenario, while we ping HostB from HostA the ARP packet goes all the way from host A to host B in order to find the MAC of hostB."" does not look like it's correct. ARP would be resolved for the Default Gateway's IP address from Host A's iperspective. This ARP packet would be the first packet to travel on the wire between Host A and Switch connected to it. ARP would eventually get resolved for Host B as well however it is not a direct ARP packet from HOST A to HOST B.
For the second part of your question, consider if everyone in this world would have there own house numbers and nothing else, no street name, no city, no state, no country. How difficult would it be for the Post office to deliver postcards? They would have to remember each and every house number and there would be no scalability.
In the same way, we need two identifiers for every machines location
1. MAC: it changes at every hop, which is similar to Street address
2. IP: It remains same, similar to House number
ARP packet are contained in the same broadcast domain, a router is a device that limit the broadcast domain. So this means that the ARP packet generated by the host A will not go beyond Router A. As Bhishma mentioned, the ARP will be replied by the Router A since it is Host A's default gateway to reach Host B.
>>> ARP packet generated by the host A will not go beyond Router A.
Now we have MAC resolved till Router A. But we need MAC of HostB. What will happen going froward.
Router A will initiate ARP packet to find MAC of host B or Router B will initiate?