Now assume that A and B are on different networks N1 and N2. In this situation A needs to identify some gateway on N1 that can deliver the packet on N2, and sends the datagram (using ARP) to that gateway. The gateway, when it receives the message either delivers it directly to the host or forwards it to some other gateway, depending on the internet address of the destination.
How does a node find a gateway for a network?
It maintains an internet routing table,
that consists of pairs (N, G),
where N is an internet network address and G is an internet
This table is updated dynamically to optimize the routing.