If the port is not in use, how can bind fail?

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.