Possible Duplicate:
How does Subnetting Work?
Imagine there is a small network with 2 subnets. Both of the subnets have their own switch (means: all machines on that subnet share the same switch). Both of the switches are connected to a router. The router is connected to the internet.
I want to understand the procedure of how a machine A in such a subnet contacts
- another machine B in the same subnet
- another machine C in the second (and therefore different) subnet
- another machine D on the internet
From what I unterstand:
In all 3 cases, machine A compares the target IP to its own subnet-mask. Now, machine A knows whether the target machine is located in the same (sub-)network or not. Is this correct so far?
If the target IP is located on the same (sub-)net, there is not much to do. Machine A just sends its data directly to machine B via the switch, there is no need for the router to intervene.
If the target IP is located in another (sub-)net, like machine C in the second subnet, machine A has no direct route. Therefore, it looks for its default-gateway (in this case the gateway is the router I think) and sends its data to the router. The router does some network address translation and delegates the data to machine C. I think it is the same procedue as for machine D on the internet.
I'm especially interested in how machine A knows whether to use the default-gateway/router or not. Is it just like I mentioned by comparing the target IP with the own subnet-mask? Or maybe I'm wrong here and it is not the job of machine A to determine that at all?
Thank you