If the port is not in use, how can bind fail?
When deploying a webserver on a server today,
Prompt me bind port failed,
I used to use netstat to check whether it was occupied!
After sharing the question, awesome colleagues found ip_local_port_range.
This corresponds to the/proc/sys/net/ipv4/ip_local_port_range file.
After opening it, I found that its content is:
1024 65000
Then I checked. The two numbers define a port range.
This file specifies the available port range of the so-called "temporary port ".
For example, a program requests a service outside the local machine through a socket,
The requirement of the internal socket is that the dual transmission of communication is an ip address and a port,
During the request, only the ip address and port to be requested are specified, and the local ip address and port are not specified,
In this case, a temporary port is automatically allocated according to the Linux policy.
The valid range of this temporary port is ip_local_port_range.
Ip_local_port_range also has a hidden attribute, which is the port in the temporary port range and cannot be bind.
That's why I first encountered the problem.
When I want to edit this file to modify the range, the file cannot be saved after modification.
Then I searched for it and said that it would be permanently modified. You can:
Vim/etc/sysctl. conf
Modify net. ipv4.ip _ local_port_range.
Save and run sysctl-p to make it take effect.
This article permanently updates the link address: