From: Javier Martinez <tazok.id0@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Re: Linux ephemeral port range defaults to "broken".
Date: Thu, 7 Aug 2025 16:25:55 +0200 [thread overview]
Message-ID: <b6138f50-5d31-4b45-91f9-3fb53bcf20e9@gmail.com> (raw)
In-Reply-To: <1072bk9$rvl$1@ciao.gmane.io>
[-- Attachment #1.1.1: Type: text/plain, Size: 3211 bytes --]
iptables -A OUTPUT -p tcp --sport 55500 -j DROP
Since ephemeral ports are used by clients and selected randomly, you
force to switch another one.
Unpriv ports used by services not started by root are the irrelevant
ones. No all people has "bittorrent" in their systems and need it
available, neither nobody has ejabberd and needs this port free. Anyone
can use netcat to listen anything to your reserved port since ports
above 1024 are for use FREELY. Netcat will not check if the is reserved,
only if its free. If the port is below 1024 and has not privs, kernel
will stop it. But just because a permissions question.
If I want clone a harddisk image from my system to a remote one I will
switch the first one above 1025 to put ncat/netcat, if it fails because
its used I would switch another one.
If one admin needs one of them available because will use this service
could use iptables to forbid using it.
Getting unpriv services hardmasking ports in one system I think it's a
silly and crazy idea and a waste of resources including a security risk
because source ports shall be selected randomly and is not the same
switching between 10000 ports and switching between 32767 in strength of
random. This is worse if your system has a lot of clients.
Neither no system will use ALL unpriv reserved ports to unpriv services.
So you can't reserve 25000 (or more) ports to be able some day to use
"one of them" having the other permanently unused.
DNS protocol is an example that not all ideas standarized are good
ideas, as with DNSSEC or with the lack of randomized source of dns queries.
El 7/8/25 a las 16:01, Grant Edwards escribió:
> On 2025-08-07, Javier Martinez <tazok.id0@gmail.com> wrote:
>
>> Also if you try to use one port from 32768 to one service you will
>> be able to do so if it's not used by any other.
>
> Right, but the problem happens when you do need to bind to a specific
> port (e.g. 44818) and it's already in use as a local ephemeral port.
>
>> Ports below 1024 has root privileges (CAP_NET_BIND_SERVICE) because
>> of this, this services are critical, services from 1024 dont because
>> they are not reserved to root.
>
> True, but not relevent.
>
>> Also, you can restrict using ports with iptables if you need for
>> example. So, if you need this port always available, tell iptables
>> that drop any connection from.
>
> I don't understand.
>
> 1. We don't care what remote source port incoming connections are
> coming from. The remote ports used in connections don't conflict
> with local ports.
>
> 2. Iptables can't prevent a socket from being bound to a particular
> local ephemeral port. I guess if iptables forces the TCP handshake
> to fail, the socket will _probably_ be closed by the application.
>
> The right answer is to use sysctl to reserve specific local ports
> within the ephemeral range via net.ipv4.ip_local_reserved_ports.
>
> I know how the system works. I know how to fix the problem. My
> question was historical: why/how did Linux end up violating the
> standards by default?
>
> --
> Grant
>
>
>
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3145 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2025-08-07 14:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 1:38 [gentoo-user] Linux ephemeral port range defaults to "broken" Grant Edwards
2025-08-07 3:49 ` Alexandru N. Barloiu
2025-08-07 6:44 ` Zhixu Liu
2025-08-07 13:04 ` Javier Martinez
2025-08-07 13:12 ` Javier Martinez
2025-08-07 14:01 ` [gentoo-user] " Grant Edwards
2025-08-07 14:25 ` Javier Martinez [this message]
2025-08-07 14:37 ` Javier Martinez
2025-08-10 1:54 ` [gentoo-user] " Grant Taylor
2025-08-10 21:13 ` [gentoo-user] " Grant Edwards
2025-08-10 21:25 ` Javier Martinez
2025-08-10 21:35 ` Grant Edwards
2025-08-10 21:28 ` Grant Edwards
2025-08-10 21:30 ` Javier Martinez
2025-08-10 21:39 ` Grant Edwards
2025-08-10 21:43 ` Javier Martinez
2025-08-10 22:55 ` Grant Edwards
2025-08-10 23:12 ` Javier Martinez
2025-08-10 21:59 ` Javier Martinez
2025-08-10 23:00 ` Grant Edwards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b6138f50-5d31-4b45-91f9-3fb53bcf20e9@gmail.com \
--to=tazok.id0@gmail.com \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox