# Bind before connect

DevFeed: [Bind before connect](<https://devfeed.tech/articles/bind-before-connect-38934.md>)

Original publisher: [Read original article](<https://idea.popcount.org/2014-04-03-bind-before-connect>)

Author: Marek

Published: 2014-04-02T22:00:00Z

Content type: tutorial

Language: en

Sources: [Marek Majkowski](<https://devfeed.tech/sources/marek-majkowski.md>)

Topics: [Linux Kernel](<https://devfeed.tech/topics/linux-kernel.md>), [TCP/IP](<https://devfeed.tech/topics/tcp-ip.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [linux](<https://devfeed.tech/tags/linux.md>), [linux-kernel](<https://devfeed.tech/tags/linux-kernel.md>), [nat](<https://devfeed.tech/tags/nat.md>), [port](<https://devfeed.tech/tags/port.md>), [python](<https://devfeed.tech/tags/python.md>), [socket](<https://devfeed.tech/tags/socket.md>), [tcp-ip](<https://devfeed.tech/tags/tcp-ip.md>)

## AI overview

This article explains how the Linux kernel allocates source ports for TCP/IP connections, including ephemeral port selection, port reuse, connection limits, and the bind-before-connect technique.

## Source excerpt

Bind before connect A TCP/IP connection is identified by a four element tuple: {source IP, source port, destination IP, destination port}. To establish a TCP/IP connection only a destination IP and port number are needed, the operating system automatically selects source IP and port. This article explains how the Linux kernel does the source port allocation. Ephemeral port range To establish a connection BSD API requires two steps: first you need to create a socket, then call on it.