problem for network switch

If we have two host with same ip on the same switch and a packet comes for that IP, then how will the switch know where to send the packet. Will it send to both hosts or only one of them, if one then why?


Solution 1:

bdonian's answer is correct about MAC addressing, however the real-world answer is

"Unless you're doing some form of link aggregation it is an incorrect network configuration - fix it."

Multiple hosts with the same IP on the same network without proper switch configuration are an incorrect network configuration and the results are inconsistent. Many things factor into "what will happen". Generally, expect problems from inconsistent behaviour to the point of no traffic.

If you want multiple hosts sharing a single IP for fail-over or load balancing that is known by many names; bonding, trunking, link-aggregation, etc., and usually needs a switch that supports one or more of these methods. http://en.wikipedia.org/wiki/Link_aggregation

Solution 2:

Network switches don't examine the IP of the packet; they examine the destination MAC address. Things would go something like this:

  1. Sending host A wants to send a packet to IP X.
  2. Host A sends a broadcast ARP request for IP X.
  3. Switch takes note of Host A's MAC address and switch port.
  4. Both Hosts B and C respond to the broadcast ARP request with a unicast ARP reply containing their MAC address.
  5. Switch takes note of Host B and C's (distinct) MAC addresses and switch ports (but not their IPs!)
  6. One of the two replies arrives first - assume host B.
  7. Host A makes a note that IP X = Host B's MAC.
  8. Host A sends a packet to Host B's MAC and IP X
  9. The ARP reply from Host C arrives. Host A may or may not overwrite the entry for IP X.
  10. The switch matches Host B's MAC address and forwards the packet to Host B's port.
  11. Host B receives the packet.