Let’s assume that we have two hosts on different networks – A and B, we want them to communicate with each other, what will happen when host A will try reaching the host B for the first time (arp cache empty) :

As we can determine by ip and subnet mask combination that host B is on another network , Host A will send a broadcast packet which will contain the following fields :

HW : 1 (Ethernet)

Protocol : 0x0800 IP

HW length : (6) 48 bit

Protocol length : (4) 32-bit

OPCode : 1 (Request)

H/W Source : aa:aa:aa:aa:aa:aa – MAC of host A

Protocol source : 192.168.0.2 – IP of host A

HW Dest – ff:ff:ff:ff:ff:ff – MAC of broadcast address

Protocol dest 192.168.0.1 – ip of gateway

Gateway will respond with ARP reply

HW : 1 (Ethernet)

Proocol : 0x0800 IP

HW length : 6 48 bit

Protocol length : (4) 32-bit

OPCode : 2 (Reply)

H/W Source : gg:gg:gg:gg:gg:gg – Gateways MAC

Protocol source : 192.168.0.1 – IP of gateway

HW Dest – : aa:aa:aa:aa:aa:aa

Protocol dest : 192.168.0.2 – IP of host A

The same will happen from other side – if gateway has no ARP entry for host B it will broadcast the ARP request to same broadcast domain(let’s assume we are using only one router) it will get a response from the host and will save its address to arp cache.

After request reply exchange we will have the gateway in our arp-cache now we can send the packets to B using the gateway.

Host A will send a packet to default gateway with destination MAC of default gateway and destination IP of host B.

Before sending the packet further gateway will change the source MAC to its own, destination IP will be left the same.

Host B will reply, MAC of gateway will be the dest MAC, and ip of host A will be dest IP.

We need not to forget about :

Gratuitous ARP – in case if machine is changing it’s MAC or services are being moved, we can have a wrong data cached in ARP caches of devices, to update it machine can send gratuitous arp requests.