So, if one PC will use another PC's IP address for ARP resolution, how does the PC sending the ARP Request even know which IP address to call for in the first place? What happens in a scenario where the PCs are directly connected (i.e. there is no intermediary network device like a switch)?
3 Answers
You're correct in thinking that the two machines will have no way of knowing each other's IP addresses initially, and there are a few different ways in which this problem can be solved.
In a directly connected scenario in a home network with windows PCs, chances are that NetBIOS will be used for name resolution. You can find out more about this protocol in the appropriate RFC, here: https://www.rfc-editor.org/rfc/rfc1001
You can think of this as working in a similar way to ARP, insofar as the computer who wants to find out the IP address associated with a certain name will send out a broadcast message to every device on its subnet to find out if any of them have the name in question.
Once the target device has replied, the original machine then knows which IP to use for this name, and also vice versa, since the NetBIOS broadcast contains the same information about the sender.
There's good answer with details about NetBIOS here as well: https://serverfault.com/questions/352305/why-can-windows-machines-resolve-local-names-when-linux-cant . I don't know much about apple devices, but I believe that they use a similar protocol called "bonjour", although someone may correct me on this, and on linux, you're likely to come across Avahi (http://www.avahi.org/) as the solution to this problem.
In a non-windows situation, or in a large business network where NetBIOS is likely to be disabled because of security concerns, name resolution is likely to be controlled via DNS. Servers may have their DNS server addresses hard coded, and workstations are likely to receive their DNS server information via DHCP. Quite often the DNS and DHCP servers will be running on the same host.
DNS is pretty complicated. If you want to REALLY understand how it works, the rfc is here: https://www.ietf.org/rfc/rfc1035.txt , however the wikipedia article is probably good enough for a basic understanding.
The basic idea though, is that if a computer doesn't know what IP address is associated with a given name, it can ask it's DNS server. Assuming that your network is set up correctly, when a DHCP lease if given out, or a static IP address is assigned to a machine, a DNS record should also be created on the DNS server.
Finally, most operating systems have a "hosts" file, which contains a list of names and associated IP addresses. If there is an entry in this file for a given name, then the OS will just use that IP address and be done with it. On a windows machine, this is located at C:\windows\system32\drivers\etc\hosts. By default it's pretty empty, you just have one entry mapping "localhost" to 127.0.0.1.
-
Ha, I always wondered why I had to enter a computer's host name when initially configuring a host! So, if I have this right, then the computer's host name is used by NetBIOS for a NetBIOS name and through NetBIOS name resolution, a PC can learn about the IP addresses on its subnet with which it may use ARP resolution to learn their MAC addresses as well? Jul 15, 2015 at 17:28
The ip is configured into the application that does the connection as either a dns name(resolved to ip via dns server) or as a IP static IP.
There are also auto-discovery protocols that utilise broadcasts and multi casts to advertise and find services. e.g. avahi
If pc's are auto configured using DHCP, the dhcp lease includes information such as DNS server ip, GW-ip, and can even include additional auto configuration information.
Your initial question seems to be about name resolution, but on your comment bellow you ask
How ARP resolution is performed.
I'll try to address that question.
A brief explanation of ARP resolution
When a network device needs to find the MAC address of an IP it will send a packet with destination MAC address FF:FF:FF:FF:FF:FF
.
This is considered a broadcast mac address so the switch will simply flood the packet to all ports (if vlans are used then only to the ports belonging to the same vlan).
The broadcast packet is an ARP Request
message, essentially asking every device on the network 'Who has this IP?'
All the devices will receive the ARP Request and the one that has the IP configured will reply back with an ARP Reply
message from its MAC Address to the device's MAC address that sent the ARP Request.
So it receives the reply and adds the IP <> MAC pair to it's ARP table cache.
For as long as the entry is in cache, whenever it needs to communicate with that device it will know how to send the packets directly to its MAC address.
If the entry is expired, it will re-sent an ARP Request
message and the process starts from the beginning.
This is a very crude explanation of course. There are many tutorials explaining this in great detail.
With a quick google search I came up with a nice one with graphs and all :)
http://www.omnisecu.com/tcpip/address-resolution-protocol-arp.php
http://www.tummy.com/articles/networking-basics-how-arp-works/
Now, to answer your question regarding 2 devices directly connected, the same principle applies in that case too. ARP resolution works the same way weather it's a direct connection or using a switch with tens of devices.
how does the PC sending the ARP Request even know which IP address to call for in the first place?
- Well why would one PC send an ARP in the first place, why would a PC ever need to know the IP of another? To connect to that PC of course! I open my browser an tell my computerI want to connect to www.google.com
so my PC has to ARP out for my default-gateway so start the process of DNS resolution and eventually TCP connectivity to a web server.