17

My understanding is there are 2^32 - 1 possible IPv4 addresses, and 2^16 - 1 possible ports. Which gives ~2^48 addresses.

The additional 2^16 additional ports seem almost insignificant considering the IPv6 address space is 2^80 times larger than the number of IPv4 addresses * ports. With the 2^128 possible IPv6 addresses, why do we need ports at all?

Why not assign each application, tab, etc... its own public IPv6 address?

13
  • 2
    Ports are addresses for some transport protocols. TCP and UDP use ports, but they are not the same ports despite using the same port number range. TCP port 12345 is not UDP port 12345. Other transport protocols may use other or no addressing. Unfortunately, the NAT variant, NAPT, only supports TCP, UDP, and ICMP, stifling existing and new protocols and innovation. IPv6 restores the IP end-to-end paradigm, allowing other existing and yet-to-be-developed transport protocols.
    – Ron Maupin
    Aug 31, 2022 at 17:03
  • 7
    Note that this mentality of ‘we have plenty of space’ is part of why we’ve run out of IPv4 addresses. Sep 1, 2022 at 1:28
  • 3
    I think the answer here is twofold: 1. Existing software should work mostly the same and there are entrenched patterns of working with ports. 2. General complexity creep: on top of addresses and ports, IPv6 added scopes, to make things more fun (en.wikipedia.org/wiki/…)
    – oakad
    Sep 1, 2022 at 6:20
  • 3
    The real question here is: What would even be the advantage or rather what problem is OP trying to solve? I think the question stems from a misunderstanding of what IP addresses and ports (TCP/UDP) are and how they relate, which the given answer already addresses.
    – Num Lock
    Sep 1, 2022 at 8:30
  • 3
    My original thinking was that, conceptually, it makes more sense for the application/process to be the addressable entity rather than the hardware device it happens to be running on. Ports seem to be a workaround, similar to NAT devices, for reducing our use of IP addresses?
    – Josh
    Sep 1, 2022 at 18:41

5 Answers 5

25

An IP address targets a host on the network layer. Transport layer ports multiplex an L4 protocol within a host (to different processes/services). Both are different things on different layers.

Basically, if you'd repurpose IPv6 addresses (or bits) for host-level multiplexing you'd gain very little but you'd break logic compatibility between IPv4 and IPv6. A transport layer protocol works the same way on any IP version.

12
  • 6
    With IPv6, it's very normal for a single host to have many addresses and create them on-the-fly. You would gain some protocol simplicity, as well as some privacy.
    – user253751
    Sep 1, 2022 at 0:41
  • 4
    It'd also make it very hard to support multiple protocols from a single domain name. For example, the host(s) at the IP(s) that www.example.com resolved to could support HTTP or HTTPS, but not both (at least without doing unpleasant things to the protocols). With ports, I can run HTTP, HTTPS, SMTP, POP, IMAP, IMAPS, SSH, etc services all under a single domain name if I want to. Sep 1, 2022 at 7:25
  • 1
    @GordonDavisson I think the OP referred to something in the line of using part of the IPv6 address for L4 multiplexing. Also, domain names don't necessarily relate to IP addresses - you can run thousands of WWW or SMTP domains behind a single IP address.
    – Zac67
    Sep 1, 2022 at 8:01
  • 3
    @GordonDavisson a separate issue really - SRV records solve this (if only they'd be enabled to all protocols)
    – user253751
    Sep 1, 2022 at 8:53
  • 3
    @Zac67 I think this is the closest answer, I disagree with the "gain nothing" but agree that what is gained is very small compared to the cost/effort associated with completely changing how IP works...
    – Josh
    Sep 2, 2022 at 8:25
6

Why do we need ports with IPv6?

As Zac67 already said, it was intended to make IPv6 as compatible to IPv4 as possible to ensure that existing programs need not to be changed too much.

Keep in mind, that in IPv4, the destination port of a TCP connection also specifies the type of higher-layer protocol:

80 for HTTP, 443 for HTTPS, 23 for Telnet and so on.

So we need the TCP port in IPv6 as indication of the higher-layer protocol type if we want to be compatible to IPv4.

Why not assign each application, tab, etc... its own public IPv6 address

I was already thinking about this: Doing this would allow implementing certain additional security and privacy features. So I can imagine that this will actually be done in the future.

And of course: We can get rid of URLs like https://example:8443/: Instead of using different ports (8443) on server side, we can simply use multiple IPv6 addresses.

However, it would still not allow us to get rid of the source port of a TCP connection:

I rembember some web-based application that requires two HTTP(S) connections to be established between the client and the server at the same time.

In this case, the server will surely check if both connections come from the same client (this means: same source IP address).

However, this means that both connections have the same two IP addresses and the same destination port (443 in the case of HTTPS). Therefore, they must have a different source port.

And if IPv6 should be compatible with IPv4, this web-based application must work the same way with IPv6 as it works with IPv4.

5
  • 2
    The predecessor of IP actually included the TCP function in the network protocol, but that proved to be a problem (for example, it was unusable for real-time protocols.)., so it was separated in IP to allow the use of other transport protocols. Unfortunately, we got stuck with only TCP and UDP because of NAPT. Many people would love to use SCTP or build a new transport protocol. You cannot use most routing protocols across NAPT, and have to create tunnels to get around that. IPv6 solves all that by restoring the IP end-to-end paradigm.
    – Ron Maupin
    Sep 1, 2022 at 12:39
  • @RonMaupin Isn't UDP the same as IP with ports? So NAPT isn't a restriction.
    – beroal
    Apr 26 at 10:06
  • 1
    @beroal What does "IP with ports" mean? An IP packet contains a field that specifies the type of data in the packet (UDP, TCP, GRE, ICMP ...). Because this field has a value in the range 0...255 and none of these values means "raw data", you cannot just send "raw data" over IP. (The closest you can do is specifying your own UDP-like protocol that uses 0 instead of 8 bytes UDP header.) On the other hand, UDP does not contain any information about which kind of data is sent, so you always send "raw data" over UDP. Apr 26 at 17:29
  • @beroal, IP, neither IPv4 nor IPv6, has any idea about ports. Ports are transport protocol addresses for some transport protocols (not all transport protocols use ports). Also, while the port number range for transport protocols like TCP, UDP, SCTP, DCCP, etc. is the same (0 to 65535 because it is a 16-bit unsigned integer), the port numbers of one transport protocol are not the same as those of another, despite being the same number. For example, TCP port 12345 is not UDP port 12345, nor is it SCTP port 12345.
    – Ron Maupin
    Apr 26 at 21:13
  • @beroal, NAPT must maintain a table for each protocol, which is why it is restricted to TCP, UDP, and ICMP. There is a table for TCP port translations, a table for UDP port translations, and a table for ICMP Query ID translations. Trying to add other protocols to NAPT translations would involve changing NAPT devices all over the world, and it would be even more resource intensive than NAPT already is, often requiring more RAM and/or a faster CPU, and NAPT may use dedicated hardware needing replacement for other protocols. The three protocols it does support are deemed "good enough" for now.
    – Ron Maupin
    Apr 26 at 21:19
6

I think the OP is not so much saying that we should roll ports specifically into the routable address scheme of the internet, but instead why not give every application/process/thread its own unique, routable address?

It's definitely a valid question, and you're not the first person to wonder this - to quote John Day "Networking is IPC and ONLY IPC".

Currently, this kind of thing has to be handled at the application layer - if I'm visiting Facebook on my phone over cell signal and then my phone switches over to WiFi, technically my source IP address (and port) has changed completely from Facebook's perspective, and it's only the tokens passed by my browser that are accepted as being the same (application-level) session.

But why stop at doing away with ports? Consider the situation with phone numbers - a phone number is just a poor proxy for specifying the identity of the person you want to speak to. That's why phones have contact lists - phone numbers are just a leaky bit of implementation that we want to ignore as quickly as possible. It's why DNS was invented - the authors of the Internet protocols chose to implement a centralized/hierarchical naming authority system versus your phone's local contact list, but same idea.

What you will want to read about are alternative Internet protocol proposals like John Day's Recursive Internetwork Architecture (RINA), where he critiques several historically accumulated design flaws in TCP/IP and the rest of the Internet protocol stack and proposes RINA as a solution.

Specifically to your question, a couple of bullet points out of John Day's critiques are relevant:

  • Multihoming: the IP address and port number are too low-level to identify an application in two different networks. DNS doesn't solve this because hostnames must resolve to a single IP address and port number combination, making them aliases instead of identities. Neither does LISP, because i) it still uses the locator, which is an IP address, for routing, and ii) it is based on a false distinction, in that all entities in a scope are located by their identifiers to begin with;[3] in addition, it also introduces scalability problems of its own.[4]
  • Mobility: the IP address and port number are also too low-level to identify an application as it moves between networks, resulting in complications for mobile devices such as smartphones. Though a solution, Mobile IP in reality shifts the problem entirely to the Care-of address and introduces an IP tunnel, with attendant complexity.

Whether you agree with him or not (as far as I know this proposal doesn't have a ton of traction), the flaws he points to and solutions he proposes are quite thought provoking.

3
  • "the flaws he points to and solutions he proposes are quite thought provoking" and extremely cost prohibitive, requiring many billions of dollars to replace existing infrastructure, and applications. Simply trying to replace IPv4 with IPv6 (going on almost 30 years) is a piece of cake compared to the thought provoking solutions.
    – Ron Maupin
    Sep 1, 2022 at 22:14
  • 2
    @RonMaupin No doubt, but still worth thinking about - many existing net technologies are stuck in a suboptimal state because of adoption critical mass, and IPv6 is a stark example of how painful it is to change even when it's necessary. At least recognizing flaws in existing protocols allows us to reimagine the use of existing protocols, like REST reusing the verbs of http.
    – Blackhawk
    Sep 1, 2022 at 23:33
  • 1
    @RonMaupin do you think it would be worth making that point explicitly in the answer for posterity? i.e. that proposing a replacement of the existing internet protocol suite is infeasible, but that reimagining or repurposing has found some success?
    – Blackhawk
    Sep 1, 2022 at 23:42
2

You need something to say "this bit of data coming in from the NIC needs to go to this process."

This is different than "which host/network does this data need to go".

IP addresses are processed by your router and potentially other carrier grade routers to determine where to move your data.

Those devices do not have the ability to, for example, reach into your PC and deposit the network data directly into the process's RAM, so they don't need to care which process on the destination wants it.

This is like adding "Give this to your cat at 2pm" as part of the address of a package you want delivered. The people processing the package don't really need to know that, they just need the address, so it's better if you put those instructions inside the package.

2
  • 2
    My home router doesn't know how to get to google's webserver either, it doesn't reach out and deliver my packets directly. It passes it along a chain of things that look through their routing tables, until it eventually gets to something that does know where to deliver it. An OS could likewise have a "routing table" that turned address into applications, analogous to how it "routes" port numbers to applications
    – mbrig
    Sep 3, 2022 at 4:03
  • An OS already does, it's called the TCP/IP stack running on that system. If your system has 1 NIC, and you have multiple processes that want to receive traffic via that NIC at the same time, what is the benefit to external routing hardware to know anything beyond the address of the NIC?
    – LawrenceC
    Sep 6, 2022 at 14:06
0

Frame Challenge: Once The ports are folded into IP addresses, you'll be burning IP addresses for a singular device, and run the risk of actually running out of IP addresses.

Currently in IPv4, the number of valid ports is 65,535 - but 0 - 1023 are restricted or reserved port numbers (Often reserved by specific company processes as well - for example, apparently Apple QuickTime, and Remote Desktop Protocol does.

Natural Address Translation takes advantage of the fact that, for most users, which unrestricted and unreserved port being used generally doesn't matter for the average use case, and doesn't need to be aligned between client and server, so we can re-map them. But what made it required to be a thing that we went with was that IP address blocks were bought by companies in large, "We'll never run out of numbers to assign!", well...numbers. Large enough to run out.

On top of this, once machines move around and switch ISPs, then they would run through more IP addresses, and their previous one would have to be expired when routing to them.

With a single IP address per machine, you can "keep" that old IP address assigned to that older device, even if it temporarily leaves where it was assigned the IP address from for a short time (More likely to be a mobile machine, or a laptop), and keeping those lower will help.

Granted, 2^128 is a lot of IP addresses, but ports will allow us to avoid running into a similar version of the problem with IPv4 thinking it had more than enough IP addresses for everyone and their dog.

11
  • 1
    There are three port ranges. "Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535)" and "System Ports are assigned by the "IETF Review" or "IESG Approval" procedures described in [RFC8126]. User Ports are assigned by IANA using the "IETF Review" process, the "IESG Approval" process, or the "Expert Review" process, as per [RFC6335]. Dynamic Ports are not assigned." and "Assigned ports both System and User ports SHOULD NOT be used without or prior to IANA registration."
    – Ron Maupin
    Sep 2, 2022 at 22:39
  • 1
    Also, the first and last port number in each of the three ranges is reserved and should not be used. 0, 1023, 1024, 49151, 49152, and 65535.
    – Ron Maupin
    Sep 2, 2022 at 22:42
  • 1
    IANA maintains the Service Name and Transport Protocol Port Number Registry. Each port listed includes the transport protocol, and it is quite possible that the same port number has a different purpose for different transport protocols.
    – Ron Maupin
    Sep 2, 2022 at 23:02
  • 1
    Port numbers are addresses for some transport protocols, and despite the same number range, each transport protocol port is only for that protocol. TCP port number 12345 goes to the TCP process, and UDP port 12345 goes to the UDP process, and each of those processes could have completely different applications using the same port number because the are not the same ports.
    – Ron Maupin
    Sep 2, 2022 at 23:02
  • 2
    @AlexanderThe1st maybe, but on the other hand, see the 4th to last paragraph of an old answer of Ron's here. IPv6 is supposed be liberal with addresses, and its deliberately trying to break the v4 habits of "conservation"...
    – mbrig
    Sep 3, 2022 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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