---
name: "IP_LOCAL_PORT_RANGE"
section: "2const"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/IP_LOCAL_PORT_RANGE"
---

# IP\_LOCAL\_PORT\_RANGE(2const)

default local port range

## NAME

IP\_LOCAL\_PORT\_RANGE - default local port range

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <netinet/in.h>  /* Definition of IP* constants */
#include <sys/socket.h>
```

**int setsockopt(int** *sockfd***, IPPROTO\_IP, IP\_LOCAL\_PORT\_RANGE,**                **const uint32\_t \****val***, sizeof(uint32\_t));** **int getsockopt(int** *sockfd***, IPPROTO\_IP, IP\_LOCAL\_PORT\_RANGE,**                **uint32\_t \****val***, sizeof(uint32\_t));**

## DESCRIPTION

Set or get the per-socket default local port range.

This option can be used to clamp down the global local port range, defined by the */proc/sys/net/ipv4/ip\_local\_port\_range* interface, for a given socket.

The option takes an *uint32\_t* value with the high 16 bits set to the upper range bound, and the low 16 bits set to the lower range bound. Range bounds are inclusive. The 16-bit values should be in host byte order.

The lower bound has to be less than the upper bound when both bounds are not zero. Otherwise, setting the option fails with EINVAL.

If either bound is outside of the global local port range, or is zero, then that bound has no effect.

To reset the setting, pass zero as both the upper and the lower bound.

## ERRORS

See [**IPPROTO\_IP**(2const)](/IPPROTO_IP/2const.md). See [**setsockopt**(2)](/setsockopt/2.md). See [**ip**(7)](/ip/7.md).

## HISTORY

Linux 6.3.

## SEE ALSO

[**IPPROTO\_IP**(2const)](/IPPROTO_IP/2const.md), [**setsockopt**(2)](/setsockopt/2.md), [**proc\_sys\_net\_ipv4**(5)](/proc_sys_net_ipv4/5.md), [**ip**(7)](/ip/7.md)
