OnCallReadyStart learning

netstat: print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships (net-tools)

netstat [address_family_options] [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e] [--timers|-o] [--program|-p] [--wide|-W] [--continuous|-c]
netstat {--route|-r} | {--interfaces|-i} | {--statistics|-s}

What it does

Prints information about the Linux networking subsystem. By default, netstat displays a list of open sockets. This program is mostly obsolete: the replacement for netstat is ss, for netstat -r ip route, for netstat -i ip -s link. It is still what many container images carry: in busybox images netstat is the busybox applet, with the short options [-ral] [-tuwx] [-enWp].

Options you will use

-t, --tcp
TCP sockets.
-u, --udp
UDP sockets.
-w, --raw
Raw sockets.
-x, --unix
Unix domain sockets.
-l, --listening
Show only listening sockets. (These are omitted by default.)
-a, --all
Show both listening and non-listening sockets.
-n, --numeric
Show numerical addresses instead of trying to determine symbolic host, port or user names.
-p, --program
Show the PID and name of the program to which each socket belongs. A hyphen is shown if the user has no permission to inspect the other process.
-e, --extend
Display additional information. Use this option twice for maximum detail.
-o, --timers
Include information related to networking timers.
-W, --wide
Do not truncate addresses by using output as wide as needed.
-c, --continuous
Print the selected information every second continuously.
-r, --route
Display the kernel routing tables.
-i, --interfaces
Display a table of all network interfaces and their counters.
-s, --statistics
Display summary (SNMP) statistics for each protocol.

Examples

$ netstat -tnp

TCP connections, numeric, with the owning program

$ sudo netstat -tlnp

listening TCP ports and their programs (ss -tlnp does the same)

$ kubectl exec POD -- netstat -tn

the connections inside a pod (busybox netstat)

Gotchas

Try netstat in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.