Home

markdown notes

Linux

Linux is a free and open-source operating system (OS) kernel, and the term is also commonly used to refer to the complete operating systems built using this kernel, known as Linux distributions.

It’s a popular alternative to operating systems like Windows or macOS, known for its flexibility, security, and open-source nature.

table of contents


Key Terms

The Kernel: Linux, in its core, is a kernel, which is the fundamental part of an operating system.

Linux Distributions: Because the kernel alone isn’t enough to run a computer, it’s combined with other software (like GNU tools) to create a complete operating system.

Common Uses:

Linux OS version

files in the /etc directory that end with -release typically contain information about the Linux distribution and version.

cat /etc/*-release

dir structure

socket statistics

Other options to see port in use

The ss command in Linux is used to display socket statistics.
It provides detailed information about network connections and sockets, including TCP, UDP, and Unix domain sockets.
It’s a modern replacement for the netstat command and offers more features and performance.

ss -tulpn | grep LISTEN

ss commands

Here’s a breakdown of common ss commands and their uses:

Basic Usage

ss: Displays all established socket connections.
ss -l: Lists all listening sockets (sockets waiting for incoming connections).
ss -a: Displays both listening and non-listening sockets.
ss -t: Displays all TCP sockets.
ss -u: Displays all UDP sockets.
ss -x: Displays all Unix domain sockets.
ss -s: Displays summary statistics about socket usage. 
ss -p: Show the process using the socket.
ss -n: Show numerical addresses instead of resolving hostnames.

Filtering

ss -o state established 'dport = :22': Displays all established TCP connections to port 22 (SSH).
# Lists all TCP sockets in FIN-WAIT-1 state connected to the network 193.233.7/24 for HTTP and HTTPS.
ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 193.233.7/24
ss sport = :80: Displays sockets with a source port of 80 (typically HTTP).
ss dport = :443: Displays sockets with a destination port of 443 (typically HTTPS).
ss -6: Displays IPv6 sockets in addition to IPv4.
ss -4: Displays IPv4 sockets (this is the default if -6 is not specified).

Advanced Options

ss -o: Displays timer information related to sockets, such as retransmission and keepalive values.
ss -m: Displays socket memory usage.
ss -i: Displays internal TCP information.
ss -p: Displays the processes using the sockets.

Other Useful Examples:
ss -tuln: Lists all listening TCP and UDP ports numerically. 
ss -a -Z: Displays all TCP sockets with SELinux security contexts. 
ss -x src /tmp/.X11-unix/*: Finds all local processes connected to the X server. 

Installation

The ss command is usually pre-installed on most Linux distributions. If it’s not, you can install it via iproute or iproute2 packages (e.g., sudo apt install iproute2 on Debian/Ubuntu systems).

Find

find . -type f -name "*my-service*.log"