Let's say I have a lot of devices which connect to a single switch, and the switch itself connects to a router which provide Internet connection.
Whenever an application on a node needs to communicate, it requires an IP address, which could be internal or external. In fact, the the IP packet is broken into smaller pieces as payload of Ethernet frames, and the node sends Ethernet frames to the switch, leaving the switch to decide where the frames should go.
What is the destination MAC address of the Ethernet frame in the following situations:
- The destination IP address is internal
- The destination IP address is external
I read somewhere that the router decides if an IP packet should be forwarded or remain inside internal network. What I am confused is where all L2 data go. Here are my 2 theories:
- The application on the host does not care and just send everything to the router. It is the router which decides where the data should go: to another internal host or being forwarded to another network.
- It is the application on the host which compares the destination IP address with its own and determines if the destination has the same network prefix. If it is on the same network, the destination MAC will be of the destination node. And if the IP is not of the same network, the destination MAC will be the router. The router has no involvement if the communication is internal.
Which one is correct?