ip_local_port_range
/proc/sys/net/ipv4/ip_local_port_range的原文解释: The /proc/sys/net/ipv4/ip_local_port_range defines the local port range that is used by TCP and UDP traffic to choose the local port. You will see in the parameters of this file two numbers: The first number is the first local port allowed for TCP and UDP traffic on the server, the second is the last local port number. For high-usage systems you may change its default parameters to 32768-61000 -first-last.
/proc/sys/net/ipv4/ip_local_port_range定义了本地tcp/udp的端口范围。可以理解为系统中的程序会选择这个范围内的端口来连接到目的端口(目的端口当然是用户指定的)。
查看
①[root@izwz920kp0myov9x9pp3l2z ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 60999
②[root@izwz920kp0myov9x9pp3l2z ~]# sysctl -a | grep ip_local_port_range
net.ipv4.ip_local_port_range = 32768 60999
修改
①临时修改
[root@izwz920kp0myov9x9pp3l2z ~]# echo 32768 61000 > /proc/sys/net/ipv4/ip_local_port_range
[root@izwz920kp0myov9x9pp3l2z ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000
@永久修改
[root@izwz920kp0myov9x9pp3l2z ~]# vim /etc/sysctl.conf
net.ipv4.ip_local_port_range = 32768 60999
[root@izwz920kp0myov9x9pp3l2z ~]# sysctl -p
现象
nginx出现以下error: failed (99: Cannot assign requested address) while connecting to upstream
2019/10/28 00:02:11 [crit] 2859#0: *78 connect() to 127.0.0.1:5000 failed (99: Cannot assign requested address) while connecting to
upstream, client: 183.17.239.138, server: 47.107.136.81, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host:
"47.107.136.81", referrer: "http://47.107.136.81/2019/8/navicat%E8%BF%9E%E6%8E%A5mysql/"
PS:SSH没有问题