2

So as the title say, how does a host know the ip addresses of other hosts on the same LAN? Is there a specific protocol for this? My first thought was that ARP could be used. But ARP seem to take an ip address as input and give the corresponding MAC address.

But say two hosts are connect in a LAN, how does host A know that B exist and that B has the ip address, say, 192.168.0.6?

1
  • 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 can post and accept your own answer.
    – Ron Maupin
    Commented Dec 17, 2020 at 14:42

2 Answers 2

5

But say two hosts are connect in a LAN, how does host A know that B exist and that B has the ip address, say, 192.168.0.6?

Simply put, the application tells it so, either by specifying the address or specifying the hostname and then issuing a DNS query.

You might ask, "why does A care if B exists?" The answer, again, is that some application wants to send a message to B. That application knows B's name or IP address.

5

But ARP seem to take an ip address as input and give the corresponding MAC address.

That is correct (for IPv4). ARP can also be used to check if an IP address is already in use (for DHCP, Zeroconf, etc).

There are several methods for finding other hosts:

The first is that the peer IP or DNS name is configured somewhere on a host. The DNS name requires DNS resolution (A record) to find the IP address. DNS server and (default) gateway IP addresses are often configured by the DHCP protocol.

The second is via broadcast (used for DHCP discovery, Bonjour, UPnP, and many other protocols), so a peer either regularly announces its presence or another peer can broadcast to get a reply. Of course, multicast can also be used instead of a general broadcast (required for IPv6 as there's no broadcast).

Both, broadcast and multicast, usually only work within the scope of the broadcast domain ie. the local link-layer segment, often identical with the IP subnet.

There's also a (crude) third method: try and error. A host may simply "sweep" a subnet, trying to connect to each possible IP address and see what turns up.

Finally, there are link-layer discovery protocols like Cisco's CDP or IEEE's LLDP that a node can use to announce its presence and capabilities to its directly connected neighbors. This method is very common with (business-grade) network devices but rarely used elsewhere.

1
  • +1 for Bonjour. That’s a “service discovery” protocol using multicast from Apple. A common use case is printer discovery. Commented Dec 30, 2019 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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