How do 2 different IPs communicate each other?
Two different IP addresses can communicate with each other by routing packets through a network. When a device wants to send data to another device, it first determines the destination IP address.
If the destination IP address is on the same network as the source IP address, the device sends the data directly to the destination IP address.
If the destination IP address is on a different network, the device sends the data to a default gateway (mostly router) on the same network. The default gateway then examines the destination IP address and determines the best path to the destination network. It then forwards the data to the next hop (another router or the destination device) on that path until the data reaches the destination device.
Each hop along the path, routers update the IP header of the packet with the next hop’s IP address and forward the packet to the next hop. This process is known as IP routing.
Routers use routing tables to determine the best path to a destination network. The routing table contains information about known networks and the next hop IP addresses to reach those networks. The router uses the routing table and the destination IP address to determine the best path to the destination and forward the data accordingly.