Android 7保留了IP端口限制

时间:2017-02-08 12:09:02

标签: android android-7.0-nougat

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

我的应用程序使用该范围内的端口,我收到错误“bind:address already used” 所以,我想知道是否有办法绕过这个限制?

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

有没有办法规避这种限制? 或者以某种方式迫使内核考虑我的变化?

1 个答案:

答案 0 :(得分:1)

来自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 Settingshttps://forum.xda-developers.com/showthread.php?t=1470125