https://access.redhat.com/solutions/3307511
Why only even number source ports are assigned as ephemeral TCP source port?
SOLUTION 已验证 - 已更新 2018年二月15日17:39 -
环境
- Red Hat Enterprise Linux 7.3 and above
问题
- RHEL host is not assigning random source ports for the new connection.
- Source port randomization doesn't work.
- RHEL 7.3 system is assigning even source ports for the connect call.
决议
-
As a part of enhancement, this is an accepted behaviour from
RHEL7.3
andabove
systems as a result of commit happened inRHEL7.3
. -
This commit segregates the allocation of ports from available local port range for
connect()
andbind()
call and will try to favoureven ports
toconnect()
call leavingodd ports
forbind()
calls.
- bind() call associates the socket with its local address, whereas
- connect() is used to connect to a remote [server] address (source port/system for a new connection)
根源
-
Before
RHEL7.3
there was no segregation of ports betweenbind()
andconnect()
call, where in order to create new connection system used to scan through all available port range/proc/sys/net/ipv4/ip_local_port_range
to find a random port and this whole process consumes a considerable amount of time on a busy system. -
On a busy host, when the system makes a
connect()
call, in order to save a significant amount of time to scan for the available source port , the port range has been by-fragmented in 2 parts : -
Even port range will favour the connect() call or will provide the priority to
connect()
call. - Odd port range will favour the bind() call or will provide the priority to
bind()
call.