linux设置预留端口号,防止监听端口被占用 ip_local_reserved_ports
2018-06-15 07:51
671 查看
1. 背景
linux服务器启动时,会对指定的端口进行监听bind,如果同一个机器上这个端口已经被使用,则监听失败,程序无法启动。
linux客户端连接服务器accept时,系统会分配本地临时端口用于网络连接。
目前是”大混部”的时代,一台物理机可能会部署多个服务,如果端口号设置不好,很可能会出现端口被其他程序占用的情况。
2. 解决方法
针对我的linux机器看看
本地临时端口配置(2个数: start, end)
cat /proc/sys/net/ipv4/ip_local_port_range 32768 61000
预留端口配置(可支持逗号分隔的多个数字,比如10000, 10005-10010)
cat /proc/sys/net/ipv4/ip_local_reserved_ports
如下面参考链接说的,有2种方法:
(1) 修改临时端口范围 ip_local_port_range,因为一个程序的端口问题修改一个机器的临时端口范围,明显减少了临时端口的使用量。代价大。
(2) 修改预留端口ip_local_reserved_ports,即使没有发生冲突也可以预先设置,防止后续端口被占用。
贴一下参考链接里面的英文
ip_local_reserved_ports解释如下: ip_local_reserved_ports - list of comma separated ranges Specify the ports which are reserved for known third-party applications. These ports will not be used by automatic port assignments (e.g. when calling connect() or bind() with port number 0). Explicit port allocation behavior is unchanged. The format used for both input and output is a comma separated list of ranges (e.g. "1,2-4,10-10" for ports 1, 2, 3, 4 and 10). Writing to the file will clear all previously reserved ports and update the current list with the one given in the input.
参考:
(1) http://www.ttlsa.com/linux/reserved-port-to-avoid-occupying-ip_local_reserved_ports/
(2) https://blog.csdn.net/bdss58/article/details/78546551?locationNum=10&fps=1
相关文章推荐
- Linux服务启动报:Address already in use 解决方法:预留端口避免占用ip_local_reserved_ports
- 预留端口避免占用ip_local_reserved_ports
- 预留端口避免占用ip_local_reserved_ports
- 预留端口避免占用ip_local_reserved_ports
- 预留端口避免占用ip_local_reserved_ports
- Linux防火墙Iptable设置只允许某ip访问某端口
- 转 -- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
- 监听端口,设置回调接收请求头问题,获取客户端IP
- linux和windows下如何知道端口是被那个程序监听占用?
- Linux系列:Fedora虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
- Linux下iptables 禁止端口和开放端口(仅供参考,里面含有iptables如何指定允许外网访问的端口号范围,以及对局域网的ip全部开放端口)
- Linux防火墙Iptable如何设置只允许某个ip访问80端口,只允许特定ip访问某端口
- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
- Linux端口占用,nodejs 监听80端口,Error: listen EADDRINUSE
- linux 查看进程端口占用情况 即ssh相关设置
- Linux防火墙Iptable如何设置只允许某个ip访问80端口,只允许特定ip访问某端口
- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)(转载)
- 修改linux端口范围 ip_local_port_range
- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)