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?

migrated from stackoverflow.com Jun 3 '11 at 19:48

This question came from our site for professional and enthusiast programmers.


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


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.

In Unix/Linux land, one host will detect the other host with the same address and simply refuse to stay on the net.

But as someone previously pointed out: if you do this, your network is broken.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy