1. Background
When the Linux server starts, the specified port is monitored for bind, and if the port on the same machine is already in use, the listener fails and the program fails to start.
When the Linux client connects to the server accept, the system allocates a local temporary port for the network connection.
Now is the "big mix" of the era, a physical machine may deploy multiple services, if the port number is not set, it is likely that the port is occupied by other programs.
2. Workaround
Look at my Linux machine.
local ephemeral port configuration (2 numbers: Start, end)
cat/proc/sys/net/ipv4/ip_local_port_range3276861000
Reserved Port configuration (Can support multiple comma-separated numbers, such as 10000, 10005-10010)
Cat/proc/sys/net/ipv4/ip_local_reserved_ports
As the following link says, there are 2 ways:
(1) Modify the ephemeral port range Ip_local_port_range, because a program port problem modifies the temporary port range of a machine, significantly reducing the amount of temporary port usage. The price is great.
(2) Modify the reserved port Ip_local_reserved_ports, even if there is no conflict can be pre-set to prevent the subsequent port is occupied.
Paste the reference link inside the English
Ip_local_reserved_ports explained as follows: Ip_local_reserved_ports-list of comma separated rangesspecify the ports which is reserved f or known third-partyapplications. These ports is not being used by automatic portassignments (e.g. when calling connect () or bind () with portnumber 0). Explicit port allocation behavior is unchanged. The format used for both input and output are a comma separatedlist of ranges (e.g. "1,2-4,10-10" for Ports 1, 2, 3, 4 and1 0). Writing to the file would clear all previously reservedports and update the current list with the one given in Theinput .
Reference:
(1) http://www.ttlsa.com/linux/reserved-port-to-avoid-occupying-ip_local_reserved_ports/
(2) 78546551?locationnum=10&fps=1
Linux settings reserved port number to prevent the listening port from being occupied ip_local_reserved_ports