It's "method A". ARP requests for addresses outside the subnet won't be sent at all. The only ARP request will be for the gateway's IP address.
If you just set up 192.168.123.1/24
for computer A and do not do anything else, it will have a routing table like this:
192.168.123.0/24
to device eth0
0.0.0.0/0
to gateway 192.168.123.254
device eth0
In such a routing table, the first entry declares that the 192.168.123.0/24
is local – accessible over eth0 without a gateway – so attempting to contact 192.168.123.42
would indeed send an ARP request for 192.168.123.42
.
However, the second entry has a gateway defined, so it is assumed to be non-local, and the OS does not bother sending ARP requests for these other IP addresses, because it already knows it cannot reach them. It will therefore directly send an ARP request for the gateway's address and nothing else.
(You can verify this by just looking at the ARP cache; ip neigh
or arp -a
depending on operating system; or by using a packet capture tool like tcpdump
or Wireshark.)
In most operating systems, you can, of course, add routes explicitly telling the OS that certain subnets are local (e.g. ip route add 192.168.124.0/24 dev eth0
).
The different networking layers are there to allow them to be swapped for different technologies.
The two layers you are talking about here are layers 2 and 3. Layer 2 in this scenario is Ethernet - from which MAC addresses arise, and Layer 3 is IP.
Ethernet only works at the local level, between network devices connected to a broadcast network "datalink", whereas IP is a routable protocol and so can target devices on remote networks.
The requirements of each of these are different. Ethernet specifies a family of technologies that allow packets to be sent and received between network devices, whereas IP defines a protocol that allow packets of data to traverse multiple networks.
Neither is reliant on the other, which is what give networking its flexibility. For example, you may choose to connect to your internet service using IP over ethernet, but in your internal network, you might choose to use IP over... paper. Where someone writes down the contents of each packet and physically walks it over to another machine and types it in. Clearly this would not be particularly fast, but it would still be IP provided the person carrying around the bits of paper respecting IP routing rules.
In the real world there are different datalink protocols that you are already using two different ones (although their addressing schemes are the same): 802.3 - ethernet, and 802.11 - wifi.
IP doesn't care what the underlying layer is.
Equally, IP can be swapped out for different network layer protocols (provided it happens for all participants). Such as ATM.
While there is nothing directly preventing the creation of a protocol that encompasses both layer 2 and layer 3, it would be less flexible, and so less attractive, and so unlikely to be used.
Best Answer
The ARP request will of course go through.
The switch doesn’t know about ARP. It only knows about Ethernet (ie. MAC addresses on Ethernet frames), not protocols on top of it. (Some switches offer advanced features like IGMP snooping, but that’s not relevant here.)
Because it’s a broadcast message, it has to be delivered to all (connected) ports. That’s all the switch cares about. It can’t know it’s really destined for computer D.