как на самом деле работает команда ping?

84424
liv2hak

Как команда ping действительно работает? В частности, где ARP (протокол разрешения адресов) входит в картину?

Мне задали этот вопрос в интервью, и я не смог придумать сценарий, в котором можно было бы использовать ARP.

21
Посмотри в ICMP. 13 лет назад 0
ARP используется для получения MAC-адреса определенного IP-адреса. Когда вам нужно отправить пакет в Ethernet, вам нужен MAC-адрес получателя. 13 лет назад 3

5 ответов на вопрос

15
PlanetUnknown

Если вы действительно хотите понять, здесь есть отличная (очень хорошо написанная) белая книга:

http://images.globalknowledge.com/wwwimages/whitepaperpdf/WP_Mays_Ping.pdf

Вот резюме ->

Ping (Program on the application layer) ------->
Opens a 'raw' socket to IP Layer ------>
IP layer (Layer 2 on OSI) packages ICMP packet and sends it

Поскольку между ними нет уровня TCP, Ping (program)он должен отслеживать все входящие пакеты ICMP и фильтровать только один из пункта назначения.

Надеюсь, это поможет.

8
David Schwartz

Assuming the ping involves a packet being sent over an Ethernet or WiFi network, ARP is used to find the Ethernet hardware address of the device that receives the outbound packet. Typically this will be the router for the LAN the machine originating the ping is on.

The typical process is:

  1. You enter a command to ping a destination.

  2. DNS is used to determine the IP address (if needed).

  3. The routing table is consulted to find the next hop towards that destination.

  4. ARP is used to find the hardware address of the next hop.

  5. The IP packet is sent to the next hop, encapsulated in an Ethernet or WiFi frame.

Единственный ответ здесь, который на самом деле отвечает на вопрос! jmiserez 8 лет назад 3
1
Heisenbug

Ping and ARP are different things located at different layers in the network protocol stack.

Ping is at network layer (or Internet layer - Have a look to ICMP protocol like pointed out by @ServerMonkey).

Arp protocol is at link level (a lower level). Arp protocol is designed to allow physical connection between network hardware, that is directly connected.

In TCP/IP network stack, every layer uses the layer below to forward its data, encapsulating it inside the low level protocol. Each layer is independent from the other and possibly unaware of the other levels specific details and implementations (this is not always true: see cross-layer function).

да. но реализация ping потребует некоторого кода на L2 (канальный уровень). ARP вступает в игру на уровне 2. 13 лет назад 0
@ Liv2hak. нет. Реализация ping лежит на нижнем уровне ссылок. 13 лет назад 0
@liv arp часто называют уровнем 2.5. ICMP часто называют уровнем 3.5. Слои больше относятся к полям, чем к коду. И если вы хотите сказать, что для реализации ping требуется код на уровне 2, то с любой реализацией чего-либо, по определению, вы не можете иметь слой без слоев под ним. barlop 9 лет назад 0
1

Ping is actually two different ICMP (Internet Control Message Protocol) packets.

To ping a host you first send a ICMP Echo Request Packet, the host will then reply with an ICMP Echo Reply.

For more information see: http://en.wikipedia.org/wiki/Ping

1
Sagar Vardekar

ARP предоставляет MAC-адрес, но иногда, если адрес DMAC отсутствует, используется широковещательный адрес.

Этот кадр, использующий широковещательный DMAC, называется кадром широковещательной передачи ARP, при этом мы получаем адрес DMAC.