0

If I have 3 machines in a local network let's say A, B and C. Now A wants to send some data to B.

Now, A needs to know the IP and the MAC of B. For simplicity, let's assume IP of B is known.

a) To know the MAC address of B, does A broadcast the message to each machine in the network and populate it in the ARP table or it simply talks to the router since router is the one with whom all device must have registered, so it should know?

b) Once IP and MAC of B are known, does A still send the message to each machine i.e. B and C and C simply rejects it, or it sends to router and router only forwards it to B, so C never gets it?

4
  • “For simplicity, let's assume IP of B is known.”—It’s actually more along the lines of: It cannot work otherwise. // Check out ARP, again.
    – Daniel B
    Commented Mar 3 at 20:13
  • a) An ARP request is broadcast locally by Host A to obtain the MAC address: who has xxx.xxx.xxx.xxx?. If Host A does not know B's IP address, then a DHCP request is first issued for it based on host name. b) Host A sends Ethernet frames addressed to Host B. Only the switches in your LAN are involved; the router is not involved.
    – sawdust
    Commented Mar 3 at 20:13
  • Are the machines in the same IP network? Commented Mar 3 at 20:18
  • @RomeoNinov yes they are in the same IP network Commented Mar 3 at 21:23

1 Answer 1

2

Before continuing, keep in mind that a home "router" works like this:

enter image description here

That is, it's a "2 in 1" box that has a router and an Ethernet switch.

In such devices, forwarding between MAC addresses is not done by the 'router' – it's all done by the Ethernet switch. The router's CPU doesn't get any packets that aren't addressed to its MAC address (or the broadcast address).


a) To know the MAC address of B, does A broadcast the message to each machine in the network and populate it in the ARP table or it simply talks to the router since router is the one with whom all device must have registered, so it should know?

The router is not the one with whom all device must have registered. A router really has nothing to do with the functioning of a single subnet – its only job is to forward packets between subnets, but within the same subnet everything is done directly between the hosts themselves, and an isolated subnet could exist without a router at all.

(The closest thing to "router registration" is the automatic IP address configuration through DHCP, which just happens to be usually run on the router for convenience but has zero effect on what the router "knows".)

What connects hosts is just Ethernet itself: packets go through Ethernet switches, or (in older days) through Ethernet hubs, or (in even older times) through a long coax cable, "directly" from one host to another. The router is just another device that's connected to the Ethernet, and it might even be completely unaware of some hosts if they haven't talked to the router specifically.

So the normal answer is "option 1": host A has to broadcast the ARP query and wait until host B itself responds with its own MAC address in the ARP response.

(Of course, networks are flexible enough that there can be exceptions that completely change the behavior, such as Proxy-ARP – e.g. in Wi-Fi networks, often the access point may answer ARP "on behalf of" its wireless devices – but they are still exceptions and not the "normal" way Ethernet networks work.)

b) Once IP and MAC of B are known, does A still send the message to each machine i.e. B and C and C simply rejects it, or it sends to router and router only forwards it to B, so C never gets it?

Technically, neither.

Host A doesn't attempt to broadcast the packet, but it also doesn't attempt to send it to the router either – it attempts to send the packet directly to B; that's why A needed to learn B's MAC address in the first place. But what happens next depends more on the network itself:

  • In modern Ethernet networks, devices are connected through Ethernet switches, which make sure that a packet addressed to B's MAC address is only forwarded to B and never seen by C (nor by the router, for that matter).

  • In very old Ethernet networks (which used either hubs or coaxial cables), all packets would reach every device; hosts would have to ignore packets that weren't a) broadcast or b) addressed to them specifically.

  • When Wi-Fi is involved, you have a mix of both types: packets that stay entirely on wired Ethernet are switched directly to the destination host, but packets that go over Wi-Fi may reach all wireless devices (because Wi-Fi is radio, and radio is broadcast by nature).

So if you have the above "Router" diagram with e.g. host A connected to 'LAN1' and host B connected to 'LAN2', what happens is:

  1. Host A learns B's MAC address using ARP.
  2. Host A sends the packet with "destination MAC = (B's MAC address)".
  3. The router's built-in switch receives it through port LAN1.
  4. The switch checks its MAC-to-port table to see which Ethernet port B's MAC is at. (Switches "learn" this based on previously seen packets.)
  5. The switch forwards the packet only through 'LAN2' to host B.
3
  • that clears up a lot of doubts. 1) "host A has to broadcast the ARP query and wait until host B itself responds with its own MAC address in the ARP response" Can't A simply ask the switch to give the mac address of B? This means A is now sending a lot of packets to hosts which don't need to be involved 2) if the host is not in the same subnet, i.e. destination is some other outside machine D, then does broadcast to B and C happens? Commented Mar 3 at 21:45
  • 1) Switches don't keep track of IP addresses, so they wouldn't know which device is "B". But because ARP results are cached, usually the amount of broadcast ARP queries in a subnet stays fairly low. (Various other junk broadcasts are usually the bigger issue.) It's only really a problem when you have hundreds of hosts in a subnet, and at that point you'd probably split the network into several smaller subnets. 2) No. Host A knows that D isn't on the same subnet so it never tries to query D's MAC in the first place; it directly sends the packet to the router's MAC instead. Commented Mar 3 at 21:55
  • alright, thanks for the answers Commented Mar 3 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .