0

What I know is that when we connect to another IP, our Public IP gets shared to the outside world, and when they address us they use our Public IP (gateway), and then the gateway directs the information to our devices using our MAC addresses, I have 2 questions:

1- If MAC addresses are used to find our devices in a network, what's the benefit of Private IP? if both of them are not shared with the outside world why do we need both of them?

2- If someone wants to address another person, they would only have the public IP of the receiver (which would be the router that contains multiple devices) how would the router knows where to direct these information? does the sender specify the local IP address of the receiver in a network or how do the sender tells the router which device to send the information to?

  • "If MAC addresses are used to find our devices in a network" Not all layer-2 protocols use MAC addresses. Some use other addressing, e.g. DLCI or VPI/VCI, and some use no addressing at all, e.g. PPP. The IEEE LAN protocols use MAC addressing, but some IEEE LAN protocols use 48-bit MAC addressing, and some use 64-bit MAC addressing. IP was developed and is maintained by one group (IETF), while the layer-2 protocols are independently developed and maintained by other, unrelated groups. IP doesn't care what layer-2 protocol is used, and the layer-2 protocol doesn't know what layer-3 is. – Ron Maupin Jan 26 at 17:17
1

1- If MAC addresses are used to find our devices in a network, what's the benefit of Private IP? if both of them are not shared with the outside world why do we need both of them?

Private IP addresses (per RFC 1918) are a workaround to delay IPv4 address exhaustion.

MAC addresses are used to forward local traffic to the desired end node. While private IP addresses seemingly serve the same purpose, the difference is that MAC addresses are physical addresses used by the (usually) Ethernet hardware to direct traffic in the LAN, and IP addresses are logical addresses that allow you to build a larger network than a single LAN segment - public or private.

Put another way, MAC addresses are meaningful inside a local LAN segment while private addresses are meaningful inside a private, coordinated network that can even span the globe. Private IPs also allow you to communicate with the Internet through address translation (NAPT) or proxies.

Note that Ethernet and TCP/IP were developed independently of each other and serve different purposes. IP is a layer-3, routable network that uses the underlying Ethernet as a local, layer-2 transport vehicle. IP can also use other layer-2 networks, even when they don't use MAC addresses.

2- If someone wants to address another person, they would only have the public IP of the receiver (which would be the router that contains multiple devices) how would the router knows where to direct these information?

Public IP addresses are routed throughout the entire Internet. Usually, you submit the packet to your ISP and they know where to send it (by global exchange of routing prefixes).

Note that routing is a refining process where each router only knows a subset of all possible routes. A router near the source address knows the source network in detail but little about the destination network - in extreme it just uses the default route. From hop to hop, each router knows less about the source and more about the destination network until the final router knows the exact interface the destination is connect on (its local segment).

does the sender specify the local IP address of the receiver in a network or how do the sender tells the router which device to send the information to?

If the destination's IP address is private it is meaningless outside its private network. A sender on the public Internet needs to use the public IP as destination. At the (public) end, the public IP is translated by a router that knows how to reach the final destination.

Most often, port forwarding or destination NAT is used where the router translates a packet destined for e.g. TCP port 80 on public IP 11.22.33.44 to TCP port 8080 on private IP 192.168.33.44. Since that router is part of the public Internet as well as the private network it can route the packet to its private IP destination.

  • Just a comment on "Private IP addresses (per RFC 1918) are a workaround to delay IPv4 address exhaustion": they are also widely used for purely internal networks, such as inside factories, banks etc, with no connection at all to the internet. These are called "Category 1" hosts in that RFC. Of course it's true that "Category 2" hosts, with partial connectivity through NAT or application-layer relay, are certainly the dominant case. – jonathanjo Jan 26 at 17:13
  • @jonathanjo Absolutely. However, on a private network you won't ever connect to the Internet you could use any IP address range you like. RFC 1918 coordinates the address space to enable connectivity to both worlds. – Zac67 Jan 26 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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