1

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:

  1. The destination IP address is internal
  2. 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:

  1. 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.
  2. 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?

  • 2
    This video perfectly talks through both situations you reference. – Eddie Sep 25 '19 at 4:07
2

IP addresses local to the sender (within its subnet) are resolved to their MAC address by ARP (IPv4) or NDP (IPv6).

MAC addresses outside the sender's subnet are meaningless. Outbound IP packets are sent to the gateway (determined by the sender's routing table) and use the gateway's MAC address.

| improve this answer | |
  • So, the application on the host compares the destination IP address with its own and determines if the destination has the same network prefix or not. 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. Is that correct? – Livy Sep 25 '19 at 3:50
  • 1
    @Livy, generally speaking yes this is true for normal network operations. There are some features that can be implemented on a network that block access between hosts on a shared network or require using the L3 gateway even for traffic destined to hosts on the same network. – YLearn Sep 25 '19 at 3:58
  • @YLearn I used to think that all internal and external data need to go from the switch to the router first (the application on the host sends everything to the router), then the router decides where these packet should go next - to an internal host or being forwarded to another network. – Livy Sep 25 '19 at 4:00
  • @Livy Communication within the subnet runs through the switch(es) alone, without router participation. – Zac67 Sep 25 '19 at 7:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.