5

If there are two PCs with same IP address on a LAN, what would happen if I ping that IP address from another PC on the same network and why?

  • How can two Pc's have the same IP address? unless one of the pc is switched off, both will be in conflict over IP address, unless you gave one of them primary and one secondary ip. – NetAdm Aug 12 '16 at 11:05
  • 1
    I think that's the question - Assuming there is a conflict, (static IPs for instance) what will happen. – Ted Quanstrom Aug 12 '16 at 18:14
  • @netadm windows will refuse to bring up an interface with a duplicate IP but linux seems to have no such protection. Furthermore even if the OS does have protetion against brining up such n interface there is still the situation of two previously disjoint networks becoming connected. – Peter Green Aug 13 '16 at 23:04
  • More or less a duplicate of Duplicate IP Address - which one wins? – Gerben Jan 3 '18 at 1:23
  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Mar 19 '18 at 3:31
12

Actually, the ping gets sent to a layer-2 address if they are on the same LAN. Assuming ethernet, the sending host may have a MAC address in its ARP cache, and the pings gets sent to the host with that MAC address (end of story).

If the host needs to send an ARP request to resolve the layer-3 IP address to a layer-2 MAC address, this is where it gets tricky. The ARP request is a broadcast so that all the hosts on the LAN get it, and both hosts with that IP address will respond with a MAC address for that IP address. The first ping packet will probably go to the first MAC address received, and if all hosts are on the same switch, or the hosts with the duplicate addresses are on different switches than the sending host, you can't predict which one will be received first. The sending host will place the first received MAC address in its ARP cache for future use (subsequent pings, normally more than one ping is sent from a single user ping).

In the meantime, the sending host will receive the MAC address from the other host, and it is supposed to update its ARP cache and use that MAC address for traffic sent to that IP address. The next pings from the ping command should go to the second host with that IP address.

You just really have no way to know in which order the hosts will respond to the ARP request, assuming the sending host didn't have a MAC address for the IP address already in its ARP cache.

4

The host that is nearer physically to your System will "usually" receive the ping. But the behaviour is undefined. Either device can receive the packets.

You could figure out which device actually receives the ICMP packets by sending an ARP request and resolving the MAC address.

Your Answer

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

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