-2

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?

learner
  • 568

4 Answers4

4

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.

bahamat
  • 5,782
3

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: https://serverfault.com/questions/49765/how-does-ipv4-subnetting-work

Hennes
  • 65,804
  • 7
  • 115
  • 169
0

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

Keltari
  • 75,447
0

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.

David
  • 9,854