From my understanding listening on a port means to request from the operating system the allocation of a given number within the range of 1-65535. The first 1024 ports are restricted to super user processes.

AFAIK any process doing an IP request needs to listen on a port and specify the port it expects the answer on within the request. However, what happens if one process claims all possible ports at once? Does the OS allow that? And if yes, does that mean that most other programs will stop working?

1 Answer 1


I don’t think there’s a way to claim all possible ports at once, at least not using the socket APIs, however, a program can attempt to bind all possible ports one after the other. If it doesn’t run out of resources, it will be able to bind all available ports, and once that’s done, no other program will be able to bind any of those ports on the same listening address.

I don’t think most programs attempt to bind a port, so most other programs shouldn’t stop working; the only affected programs will be those which need to use an already-bound port, i.e. any program attempting to use an IP socket.

Cloudflare are proposing a patch which allows BPF programs to listen on any port, and that would allow a BPF program to effectively list on all ports; see the patch and this forthcoming talk at LPC.

  • wrt your last paragraph -- that includes any program using ip sockets in any form or shape. If an ip socket is not bound, it will be automatically bound by the kernel to an ephemeral port upon the call to connect(2) or send*(2); if all the ports (in the ephemeral range on Linux -- cat /proc/sys/net/ipv4/ip_local_port_range) are occupied, that will fail, too.
    – user313992
    Aug 26, 2019 at 16:48
  • @mosvy yes, indeed, I should have spelt that out; I meant “use” in the most general sense. Aug 26, 2019 at 17:00
  • Most user processes are limited, by default, to 1024 open descriptors. That, I believe covers sockets as well as file descriptors which limits the possibilities.
    – Ned64
    Sep 2, 2019 at 8:53
  • @Ned64 yes, but that can easily be increased to allow this scenario. Sep 2, 2019 at 8:59
  • @StephenKitt Yes, by root but (hopefully) not by an attacker trying a local DoS attack (like some Windows programs did inadvertently in my youth).
    – Ned64
    Sep 2, 2019 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .