linux-network-performance
Overview
socket
There are two popular tools for inspecting the socket states (netstat and ss)
netstat gets its information from /proc/net
directly. It parses the file and prints out information based on it.
ss
was written more recently to use the netlink API
(it will fall back to proc/net if netlink is unavailable). The information in both systems is essentially the same, but netlink API
exposes more information than procfs
. so try to use ss
for socket stats if it’s available.
NOTE: netstat provides other info except socket statistics, like routing table etc.
ss command
The ss command shows socket information, pretty much like netstat does. but use netlink API
, with more details, ss
always shows socket with Local address
and Remote address
even for unix socket!!!
options
- –n, –numeric don’t resolve service names
- -r, –resolve : resolve host hostnames.
- -l, –listening display listening sockets
- -o, –options show timer information
- -e, –extended show detailed socket information
-m, –memory show socket memory usage
-p, –processes show process using socket
- –s, –summary show socket usage summary
-N, –net switch to the specified network namespace name
- -t, –tcp display only TCP sockets
- -u, –udp display only UDP sockets
- -w, –raw display only RAW sockets
- -x, –unix display only Unix domain sockets
1 | # Show all listing tcp sockets including the corresponding process |
lsof
The lsof
utility shows all the currently active file handles(open file) on the system.
1 | # which process(es) open this file |