Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Lets say I and my friend connect our computers with a LAN cable.

I ping my friend with his IP address.

How does it work?

Since we are in the same network, we don't even need IP addresses, do we?

Isn't IP addressing only relevant in case of inter-network communication?

What will the ping command do with his IP address? How will it eventually find his physical address (NIC address)? (no ARP here, because that would involve a router at the edge of the network, which doesn't apply here).

Am I wrong somewhere?

share|improve this question

closed as too broad by techie007, Tog, Moses, Mokubai, tapped-out Nov 16 '13 at 13:14

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Downvoter, care to explain? I'm willing to explain anything here. I have done my reading, but still have these questions. –  learner Nov 12 '13 at 20:20
2  
You've made many bad assumptions in this 'question'. Not all networks are IP-based. IP addresses are host-based, not 'inter-network'. ARP is required for an IP network, and the computers use ARP as well as routers, L3 switches, etc. In the end your question "how do 2 computers communicate in a single network?" is way too broad. –  techie007 Nov 12 '13 at 20:23
1  
@learner - Your asking how a network ping works which is well documented. IP Address are also required in an intra-network communication also. In an intra-network his physical address is the ip address he assigned it. –  Ramhound Nov 12 '13 at 20:25
    
Possible dupe: how does 'ping' command really work? –  techie007 Nov 12 '13 at 20:26
    
@Ramhound, What do you mean by : "his physical address is the ip address he assigned it.". Physical addresses are fixed and imprinted on the computers. –  learner Nov 12 '13 at 20:30
show 6 more comments

4 Answers

up vote 1 down vote accepted

You're asking about the OSI Network Model, even though you don't realize it, and even though the OSI model doesn't quite relate to TCP/IP.

The way computer networking works is in layers. The layers in the OSI model are:

  1. Physical (e.g., copper, fiber, etc.)
  2. Data link (e.g., ethernet, ppp, fddi, etc.)
  3. Network (e.g., IPv4, IPv6, IPX, etc.)
  4. Transport (e.g., TCP, UDP, etc.)
  5. Session (Used in OSI, but most things here are handled by layer 4 in TCP/IP)
  6. Presentation (e.g., ASCII vs. EBCDIC, or MIME)
  7. Application (e.g., HTTP, SMTP, DNS, etc.)

In order for two computers to communicate over a network they must be speaking the same network layer protocol. It doesn't have to be IPv4 or IPv6, it could be IPX or X.25. But it must be something.

We'll just assume IPv4, since that's most common.

Both computers will need an IP address. In this day and age most likely they will be assigned one from a DHCP server or will dynamically assign their own using ZeroConf. So they will have IP addresses.

What happens when you ping?

First the computer initiating the session will send a broadcast layer 2 ARP packet. ARP is Address Resolution Protocol. ARP is used to discover the layer 2 address associated with a particular layer 3 address. A broadcast is a special packet that instructs the network switch to send the packet to all physical ports with a connected link (i.e., with L1 connectivity). The computer that has the indicated Layer 3 address will respond with a unicast ARP reply. ARP happens entirely over L2 addressing (ARP results are cached for later lookup so it doesn't have to keep sending ARP requests).

Next an ICMP echo-request packet is crafted. The source L2 address will be the originating computer's Ether address. The L3 source will be the originating computer's IP address. The destination L2 and L3 address will be those discovered from the ARP. The packet is then sent over the wire to the switch.

The switch examines the destination L2 address and looks up in it's CAM table to identify which physical port has the specified Ether address. The packet is then sent over the wire on the correct physical port.

When the destination computer receives it, it first examines the L2 address to make sure that it matches the L2 address of the physical interface that received the packet. If it matches then it checks the L3 address to make sure that it matches a Layer 3 address assigned to the physical interface. If all of these check out then the packet will be handled by the upper layer protocols (in this case ICMP, handled by the kernel). If not, the packet is dropped.

For the ICMP reply things work in pretty much the same way, except that the responding computer doesn't need to send an ARP request, since it received a packet with an L2/L3 pair it can install that directly to the ARP cache instead.

share|improve this answer
    
Thanks a lot! How would the ARP part have changed if I were pinging google.com? When I use Google's IP address, what exactly sends my packet to the nearest router to me? Here ARP wouldn't be useful, since knowing the physical address of Google's computer is useless to me. It will be needed by the last router that sends it to Google. But to my computer it is useless. Also, I don't have a routing table in my computer. How then does such a packet go to the nearest router automatically? –  learner Nov 13 '13 at 11:24
    
See the link I posted. The IP packet (with the ICMP echo request datagram) will be send to the router with as destination IP an IP from google. ARP is only used on the local network (to get the MAC of the default gateway). As far as you are concerned it is ICMP/IP. –  Hennes Nov 13 '13 at 11:50
add comment

Since we are in the same network, we don't even need IP addresses, do we?

Ehm. Technically no.

But if you want to communicate over TCP/IP then you need one. And almost anything uses that.

Lets say I and my friend connect our computers with a LAN cable. I ping my friend with his IP address. How does it work?

You computer looks if the target IP is in the same subnet.
If it is (routing table check!) then it look if it has the ARP cached.
No arp -> ARP discovery Then the ICMP echo request (the ping) gets send via IP to the destination NIC (based on the destinations MAC).

How will it eventually find his physical address (NIC address)?

It will look in the ARP cache, and if the destination is not there is will broascast a package which comes down to "Who has IP number a.b.c.d?". And that will be answered by the PC with "I am MAC aa:bb:cc:dd:ee:ff. I have IP a.b.c.d."

no ARP here, because that would involve a router at the edge of the network, which doesn't apply here.

Uhn no. ARP will be used. ARP is very much local. ARP will not be used once off the local network (and thus no ARP beyond the router).

Isn't IP addressing only relevant in case of inter-network communication?

No.

I will not even try to write a nice long answer. Instead I will point you at this previously well written post: http://serverfault.com/questions/49765/how-does-ipv4-subnetting-work

share|improve this answer
    
+1 for trying to save this soul from using google –  M.Bennett Nov 12 '13 at 20:52
add comment

If you are communicating over IP, then you need an IP address. Without a destination IP address ping can not function.

share|improve this answer
    
Yes, but question is how will my computer eventually find my friend's NIC address? My only knowledge of logical address -> physical address mapping is that of ARP, which doesn't seem to apply here. –  learner Nov 12 '13 at 20:51
2  
ARP very much applies here. ARP is local only (with a router and all local computers being on the local network). –  Hennes Nov 12 '13 at 20:51
add comment

Your confusion goes deeper than even a long post can answer. You need to read a good networking textbook.

If you don't want to invest the time, you could try reading the wikipedia pages on APIPA, ARP and the difference between the network layer and the data link layer, but that's only a start.

share|improve this answer
add comment

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