2

With a normal Ethernet cable (patch cable) you use Ethernet Frames (https://en.wikipedia.org/wiki/Ethernet_frame) to send data to other computers/devices in my LAN network. In the Ethernet frame, there is a source mac address and a destination mac address. And it has a payload. The payload contains an IP package (https://en.wikipedia.org/wiki/Network_packet). How does my computer when I enter the command ping 192.168.86.40 connects to the computer and send packages without knowing the mac address used to send Ethernet frames. You need a destination mac address to send Ethernet frames which contains IP packages. And if I set up my network with a static IP address, subnet master, and a gateway IP what the mac address is for the gateway to connect. Does the computer use the broadcast mac address FF:FF:FF:FF to figure out what the gateway mac address is?

The QUESTION is: How does a computer know where to send the packet to, only with an IP address not MAC address to send Ethernet frames that contain IP packets

Zac67
  • 2,761
  • 1
  • 10
  • 21
SmileDeveloper
  • 366
  • 3
  • 10

1 Answers1

7

IPv4 uses ARP (Address resolution protocol) - the source node sends an ARP request as broadcast, asking for the destination IP's MAC address. The request is received by the destination node (ignored by anyone else) and replied to with its MAC address.

Once the MAC address is known, the source can encapsulate the IP packet in an Ethernet frame and send away.

ARP is only usable for any local IP address, ie. an address residing in the same subnet as the sender. If your local IP address is e.g. 192.168.86.2/24 the destination 192.168.86.40 is local.

Sending to an IP address outside your local subnet requires a gateway (router) - this can simply be the default gateway or another, specific gateway as indicated by the local routing table. ARP is only used for resolving the gateway IP address here. The IP packet is encapsulated using the gateway's MAC address as destination and sent out.

The gateway repeats this process - either resolving the destination IP by ARP when it's local or using its routing table to find the next hop gateway, resolve its IP address and forward to that MAC. These steps repeat until the destination is reached.

Accordingly, the answer to your question is:

  • a host uses its local routing table to determine the next hop towards the destination (which might be the destination itself)
  • the next hop's IP address is resolved to its MAC address using ARP (for IPv4)
  • the IP packet is encapsulated in an Ethernet frame addressed to that MAC and sent out

Of course, there are other link layers than Ethernet but the general process is identical with all MAC-based networks.

Zac67
  • 2,761
  • 1
  • 10
  • 21
  • So you don't use gateways to send data to another computers in your network. A gateway is only a outside communicator. (such as communicating to www.google.nl). And how does the gateway knows that there is a new device connected without using DHCP, or when it disconects? Does it uses PING? (ICMP echo requests and responses) – SmileDeveloper Jul 19 '18 at 18:36
  • A gateway doesn't need to know about devices on any of its local links. When it receives a packet to be forwarded it consults its own routing table and forwards it appropriately. Basic routers (non-NAT, non-firewall) are completely stateless, ie. they forget about a forwarded packet as soon as it's finished sending. – Zac67 Jul 19 '18 at 19:37
  • Okay. But That basic router is called a modem. It also forward packets. If it has a ip controlling system like DHCP it is a router – SmileDeveloper Jul 20 '18 at 12:54
  • *modem router. Only when it is connected ex a coax cable. Very helpful – SmileDeveloper Jul 20 '18 at 13:03
  • A modem is a modem and a router is a router. A modem encodes and decodes data onto modulated physical layers and a router forwards packets based on IP addresses. There are many devices featuring both functions but they are completely distinct. A DHCP server is something completely different still. – Zac67 Jul 20 '18 at 13:57
  • Okay, but how to format an ARP packet in an IPV4 packet. – SmileDeveloper Jul 25 '18 at 17:27
  • That is an entirely new question. ARP is not encapsulated in IP, it sits directly on top of Ethernet. Take a look at [RFC 826](https://tools.ietf.org/html/rfc826). – Zac67 Jul 25 '18 at 17:51