安卓 7 保留 IP 端口限制



在Android 7中,有一系列保留的IP端口。这在文件/proc/sys/net/ipv4/ip_local_reserved_ports中指出:32100-32600

我的应用程序使用该范围内的端口,并收到错误"绑定:地址已使用"。
所以,我想知道是否有办法绕过这个限制?

我想修改文件并排除我使用的端口。实际上,我已经植根了我的设备,修改了文件,但内核没有发现更改。即使文件已被修改,如果我重新启动设备,更改也会丢失。

有没有办法规避这个限制?还是以某种方式强制内核考虑我的更改?

从 https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt:

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.
    Note that ip_local_port_range and ip_local_reserved_ports
    settings are independent and both are considered by the kernel
    when determining which ports are available for automatic port
    assignments.
    You can reserve ports which are not in the current
    ip_local_port_range, e.g.:
    $ cat /proc/sys/net/ipv4/ip_local_port_range
    32000    60999
    $ cat /proc/sys/net/ipv4/ip_local_reserved_ports
    8080,9148
    although this is redundant. However such a setting is useful
    if later the port range is changed to a value that will
    include the reserved ports.
    Default: Empty

所以,我想知道是否有办法绕过这个限制?

我建议您使用其他端口,否则您的系统可能会变得不稳定,因为系统服务可能正在使用该保留范围内的端口。

有没有办法规避这个限制?还是以某种方式强制内核考虑我的更改?

由于您植根了设备,因此您可以尝试 sysctl .这些链接可能会有所帮助:Android Edit Sysctl 设置和 https://forum.xda-developers.com/showthread.php?t=1470125。

最新更新