r/AskComputerScience • u/Aokayz_ • Jun 10 '26
Why Use Private IP Addresses Instead of MAC?
High school student here.
In TCP/IP protocol suite, the MAC addresses are used in the link layer to send frames between devices in a LAN, ensuring that devices in the same LAN can communicate.
However, the router also assigns each LAN device with a private IP address. So how is that private IP needed? Certainly the MAC is sufficient for devices in the LAN to talk to each other, so is it for devices outside the LAN to send messages to that host? I have doubt about that, because if it's private, then no one across the internet should be able to access it. Correct?
So what is the private IP address for?
20
u/nuclear_splines Ph.D Data Science Jun 10 '26
(Pedantic clarification: the router is not responsible for assigning IP addresses, that's the DHCP server. In home setups the router, modem, DHCP server, firewall, and NAT gateway are frequently combined into a single device, but these are somewhat distinct roles from a networking perspective)
There are several answers to your question. First of all, some LAN communication protocols do use MAC addresses instead of IP addresses, such as ARP and DHCP. There's no reason you couldn't write LAN chat software that's built right on top of Ethernet frames.
However, we don't want to rewrite all our network protocols to work this way. TCP provides the idea of a "connection" and maintains packet order, re-transmits corrupt data, and other conveniences. HTTP is built on top of TCP so that it gets that functionality "for free" -- but TCP is built on top of IP, so needs IP addresses. If you wanted HTTP to run on top of Ethernet frames directly without an IP layer, you'd have to write all the code for maintaining a TCP-like connection yourself. Very tedious. Why not just use IP addresses so we can use all the same protocols regardless of whether the server is on the LAN or the WAN?
The private/public IP divide isn't really about privacy or security -- it's intended for sharing a single IP address across multiple computers to overcome IPv4 address scarcity. In fact, at many universities and some large corporations, every computer may have a public IP address with no need for NAT. In these settings you may be able to reach hundreds or thousands of computers by MAC address alone on big Ethernet trees. The IP layer is instead preferred because it dramatically simplifies routing, and in principle allows us to make connections over mediums besides Ethernet and WiFi that don't have anything similar to a MAC address.
6
u/alecbz Jun 10 '26
The IP protocol is designed around IP addresses, so anything that talks IP (or any of the protocols built on top of it, TCP, HTTP, etc.) needs to have an IP to address packets to.
3
u/MastOfConcuerrrency Jun 10 '26 edited Jun 11 '26
MAC addresses are, for the purposes of this question, essentially just random IDs. Two devices on the same LAN can have arbitrarily different MAC addresses.
By contrast IP addresses are assigned in a manner that preserves topological proximity. If you're on the same local network as other computers, then you'll notice that their IP addresses will have a large common prefix (e.g. 192.168.0).
IP-based routing is based on addresses having a shared common prefix. Network routers have a fixed size routing table and cannot store all addresses ever known. Instead they just store a table of IP prefixes (at varying lengths). When a packet comes in destined for a particular IP address, the router decides where to forward that packet based on the longest matching IP prefix in its table. This allows packets to overall be routed to the correct destination, without every router needing to know the location of every machine in existence.
TL;DR IP addresses are hierarchical in the same way as your mailing address is
2
u/AYamHah Jun 10 '26
https://ebooks.karbust.me/Technology/Computer%20Networking%20A%20Top-Down%20Approach,%208th%20Edition%20by%20James%20F.%20Kurose,%20Keith%20W.%20Ross-Pearson-9780136681557.pdf
2
u/wrosecrans Jun 10 '26
The first versions of Ethernet were local-only, didn't have IP at all, and worked basically just like you are asking about. Software had to be written to "speak" Ethernet directly.
But eventually, IP took over almost all networking because it was hardware independent. Companies that had invested in LAN's wanted to be able to route traffic between those early networks, and that meant traffic had to go over some long distance step that wasn't ethernet. So all the modern software stacks speak TCP/IP. Could you still run a TCP/IP-less LAN with only bare ethernet? It's possible. But none of your software that expects to run on a TCP/IP network would work, and you'd have no good way to connect that network to the Internet or any other network.
2
u/OldGeekWeirdo Jun 11 '26
On a small local network, just a mac address is fine. But when the network gets larger and you have to route packets, it becomes difficult to impossible to keep track of where each mac access is currently located at.
Can you imagine notifing all the routers in the area when you take your work laptop and plug it in at home?
IP addresses are based on the network you're plugged into. If you move to a new location and plug in, you're assigned a new IP address that is consistent with that location. All the routers in-between don't have to know you've moved.
TL;DR: Mac is based on the machine. IP is based on location.
1
u/DarthGamer6 Jun 10 '26
IP exists independent of the physical hardware, so devices that speak IP can talk to each other as long as there is a valid route between them. MAC addresses are typically tied to physical or emulated hardware, so they can only talk to devices that "speak" Ethernet. Having things on a network speak IP means that you can have different, potentially incompatible physical or logical mediums talk to each other without having to have a translation layer. The in-between device ("router") can just slap its own link layer header on the IP header and pass it on without having to think too much about how the different link layers relate to each other.
1
u/PLANETaXis Jun 11 '26
There are lots of reasons, but a common theme that pops up in computer science is indirection and abstraction to prvide flexibility.
Also, the whole private IP thing was a hack. The intention was for everyone to get a real IP address (like with IPv6), the designers didn't envisage so many users and so NAT was a workaround to allow a small pool of "private" addresses to be reused.
1
u/falsifian Jun 11 '26
Maybe worth noting that link-local ipv6 addresses work a bit like what you're imagining. Each network interface knows its own ipv6 link-local address without any outsude help; no DHCP server or anything similar required. Devices on the same LAN can use link-local ipv6 addresses to communicate with each other, but not with interfaces that aren't on the same LAN. These addresses are usually derived from MAC addresses.
1
u/Specialist_Cow6468 Jun 11 '26
A thing I don’t really see talked about here is the ah, problematic nature of flooding in layer 2 domains. It is very much to our collective benefit that broadcasts (or neighbor discovery for IPv6) are kept localized, at least without getting into topics which are likely to confuse the issue a bit. Suffice to say I have seen what a state scale broadcast storm looks like and it straight up killed a router.
Networking is all about abstraction. There are different needs for establishing communication at a local level (EG a LAN or broadcast domain or whatever you want to call it) vs globally.
I’m happy to chat more on the topic. I’m a network engineer with a background in provider networking / datacenter design and am likely to have some practical insight on the realities that others on this board, not that I find the other answers unreasonable. It’s just a matter of perspective
1
u/soundman32 Jun 11 '26
All of those layers are independent, and don't (really) require the lower one. Want to run TCP/IP over something that doesn't have MAC addresses? Yes, you can. In the days of Dial Up, IP over PPP or SLIP was a thing, and there were no MAC addresses in sight.
Hundreds of years ago, when men were men, and computers didn't fit in your hand, there were many different protocols (IPX/SPX, ARCNET, 10Base-T), that could sit on top of many different physical hardware. When you put a modern view on it, where (virtually) everything is the same protocol, you wonder why things were designed like that, but in the 60s-70s, when these protocols were created, they were necessary.
1
u/ephemere_sloboda Jun 14 '26
Applications are written to work regardless of whether their peer is in the same room or on the other side of the world.
The application layer interfaces to the network layer (IP) which provides this abstraction.
The IP layer interfaces to the link layer at each hop, but that's not something the application needs to worry about.
IP addresses are needed on the LAN so we don't have to reinvent the wheel with every application.
The local IP addresses don't have to be private. There are two main reasons for using private addresses:
When using IPv6, there are more than enough addresses for everyone, so public addresses are used more commonly.
0
u/high_throughput Jun 10 '26
In 1990, every computer on your LAN would get a public IPv4 address that it can use to send packets anywhere on the internet, and the internet can use to send packets back to you.
In 1995, consumer broadband started to take off, people saw the writing on the wall, and realized that in the not-too-distant future we would run out of IP addresses.
Since 2000, every computer on your LAN still gets an IPv4 address that it can use to send and receive packets anywhere, so from the computer's point of view nothing has changed, and all the old software still works without modification.
But secretly, the address you got is a mock address and your NAPT router rewrites all your traffic to make it seem like it's a publicly accessible address when it isn't.
So we use IP addresses because we need IP addresses, and the fact that the address you get happens to be private is a transparent address space saving technique that the computer shouldn't have to be aware of.
-1
u/rupertavery64 Jun 10 '26
Would you like to type a MAC address to access a device or site or ftp?
-1
u/In_the_year_3535 Jun 10 '26
It's been a while but I want say the MAC address says a lot about your device and the private IP address used between you and your gateway is shorter and less revealing. Kind of like not using your social security number for everything.
-1
u/oxmix74 Jun 10 '26
Because the networking applications on your pc are nearly all designed for tcp/ip. They wouldn't work on a network based on MAC addresses.
In a parallel universe where you had applications based on MAC address networking, the applications would not be routable.
In the early days of networking, I supported a product that used a non routable protocol. On the tech support call the customer asked "So how did you ever expect this thing to work?" I didn't have an answer.