4

In Android 7, there is a range of reserved IP ports. This is indicated in the file /proc/sys/net/ipv4/ip_local_reserved_ports: 32100-32600

My application uses a port in that range and I get an error "bind : address already used".
So, I wanted to know if there is a way around this restriction?

I thought to modify the file and exclude the port that I use. In fact I have rooted my device, modified the file but changes were not picked up by the kernel. Even if the file has been modified, if I restart the device the changes are lost.

Is there a way to circumvent this restriction? Or somehow force the kernel to take into account my changes?

Volo
  • 28,673
  • 12
  • 97
  • 125
Karim
  • 51
  • 3

1 Answers1

1

From 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

So, I wanted to know if there is a way around this restriction?

I suggest you to use a different port, or else your system may become unstable for a system service may be using a port in that reserved range.

Is there a way to circumvent this restriction? Or somehow force the kernel to take into account my changes?

Since you rooted your device you can try sysctl. These links may help: Android Edit Sysctl Settings and https://forum.xda-developers.com/showthread.php?t=1470125.

Community
  • 1
  • 1
nandsito
  • 3,782
  • 2
  • 19
  • 26