These notes were originally taken in thelinux Section and later moved here. They represent some facts about the TCP stack that might be “less obvious”.
IPv4 notes
Goodbye classes, welcome CIDR
Historically IPv4 IP addresses were organized in classes, but today the only method to assign ip address is Classless Inter-Domain Routing(CIDR).
Reserved IP addresses
127.0.0.0: this subnet is reserved for local addresses, with the most prominent one being the loopback address127.0.0.1.169.254.0.0/16(169.254.0.0to169.254.255.255): these are link local addresses, meaning packets sent there should not be forwarded to other parts of the network. Some cloud providers such as Amazon Web Services use this for special services (metadata).224.0.0.0/24(224.0.0.0to239.255.255.255): this range is reserved for multicast
RFC 1918 and private IP ranges
A private IP range means that the IP addresses in it are not routable on the public internet; hence, it is safe to assign them internally (for example, in the context of your company):
- 10.0.0.0 to 10.255.255.255 (the 10/8 prefix)
- 172.16.0.0 to 172.31.255.255 (172.16/12 prefix)
- 192.168.0.0 to 192.168.255.255 (192.168/16 prefix)
Tip
0.0.0.0 refers to all IPv4 addresses present in the machine. That’s a great way to say “listen on all available IP addresses” as a source until it turns into a known IP.
Info
The traditional usage of
routecomamand has been replaced by the more modernip route
IPv6
IPv6 uses 128-bits for addresses, meaning we can assign up to 10^38 addresses:
- Representation is hexadecimal
- There are 8 groups of 16 bits each separated by
: - IPv6 addresses can be shortened by removing leading zeros or compressing consecutive sections of 0 with
::
Tip
For example, the IPv6 loopback address
::1is the equivalent of127.0.0.1
TCP notes
Info
Today there are efforts of handling typical concerns that TCP handles such as flow control and multiplexing at applicatoin level, as the HTTP3 does.
TCP Port ranges
A port is a unique 16-bit number identifying a service available at an IP address:
- Well-known ports (from 0 to 1023). These are for daemons such as an SSH server or a web server. Using (binding to) one of them requires elevated privileges (
rootorCAP_NET_BIND_SERVICEcapability) - Registered ports (from 1024 to 49151). These are managed by Internet Assigned Numbers Authority (IANA) through a publicly documented process.
- Ephemeral ports (from 49152 to 65535). These cannot be registered. They can be used for automatically allocating a temporary port (for example, if your app connects to a web server, it needs a port itself, as the other endpoint of the communication) as well as for private (say, company-internal) services.