Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does layer 3 (network layer) recognize the IP address?

Layer 2 (Ethernet layer) recognizes the MAC address using ARP protocol. It sends a question to the whole network asking: "Which MAC address has the IP x?". That's how it recognizes the destination MAC address.

But how does Layer 3 (IP layer) knows the IP address? It is not passed to it from the transport layer (layer 4). Only the port number is passed.

I hope I am specific. Thanks in advance.

like image 407
Tony Avatar asked Feb 22 '26 15:02

Tony


2 Answers

There are two IP addresses associated with a packet, the sending (also know as source) IP and destination IP.

Sending IP - The sending IP is trivial, it is a configuration parameter of the network interface by which the packet will be transmitted. It is configured either statically or more typically in modern networks through DHCP.

Destination IP - The destination IP can be slightly more complex depending upon whether the destination computer is local or remote to the sending computer. In this case, remote means that the destination computer is not located in the same subnet as the source computer.

For remote destinations DNS servers are used for name<->IP resolution. DNS is what allows humans to use our strength, names such as www.espn.com, while computer can use their strength, bit representation of IP addresses such as 10.5.0.1. DNS resolution can be configured many different ways, but basically boils down to examining local cache to see if a prior resolution exists, and if not querying one or more DNS servers to resolve the request.

If the destination machine is local, on the same subnet, then ARP/RARP is used for MAC<->IP translation. Once again a cache is checked first, in this case the ARP cache, before creating a new ARP request (and thereby using network bandwidth).

I hope this helps.

like image 74
Gerald P. Wright Avatar answered Feb 27 '26 02:02

Gerald P. Wright


Every layer provides an interface to the layer above. It is through this interface that layer4 sends layer3, the destination IP address. layer5 (Application Layer) sends the destination IP address it wants to talk to, to layer4 which in turn sends it to layer3. Layer3 includes this in the IP packet and passes this packet to the layer2 (along with other things like MAC address of the destination etc..)

It is like giving arguments when you call a function. Suppose the interface provided by layer3 is send_packet(), layer4 calls it, may be, like send_packet(srcIP, destIP)

like image 34
nitishch Avatar answered Feb 27 '26 03:02

nitishch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!