It gets them from kernel space directly using Netlink which uses the classic sockets API.
Answer from ggiroux on Stack OverflowIt gets them from kernel space directly using Netlink which uses the classic sockets API.
I've made a comparison table (in Google Docs) (light HTML link) for converting between netstat and ss arguments. It's too big to include and update it here.
The short version of difference between short arguments is:
Arguments that require attention:
r N i g M W T v C F c A U 2 f
Arguments that are safe to leave as is:
h V l a n Z s p e o 4 6 x t u S w
The manual for Netstat says it's obsolete and that I should use ss instead, but I like Netstat's more compact and easy-to-read interface better than ss's wide and spread-out display.
Is there anything wrong with Netstat compared to ss? Which one do you use?
Videos
I've made a comparison table (in Google Docs) (light HTML link) for converting between netstat and ss arguments. It's too big to include and update it here.
The short version of difference between short arguments is:
Arguments that require attention:
r N i g M W T v C F c A U 2 f
Arguments that are safe to leave as is:
h V l a n Z s p e o 4 6 x t u S w
I stumbled across this post while researching netstat -> ss conversion. Outstanding table but I wanted to point out one thing in particular... the man page description for the netstat -s command option states, "Display summary statistics for each protocol". ss -s option in the man page states, "Print summary statistics. This option does not parse socket lists obtaining summary from various sources. It is useful when amount of sockets is so huge that parsing /proc/net/tcp is painful." These two command options return EXTIRELY different information.
For example:
$ ss -s
Total: 1365 (kernel 0)
TCP: 276 (estab 163, closed 14, orphaned 0, synrecv 0, timewait 1/0), ports 0
Transport Total IP IPv6
* 0 - -
RAW 1 1 0
UDP 24 17 7
TCP 262 246 16
INET 287 264 23
FRAG 0 0 0
as opposed to the netstat -s command output (truncated):
$ netstat -s | head -n15
Ip:
2043673568 total packets received
0 forwarded
0 incoming packets discarded
1997519606 incoming packets delivered
1359233819 requests sent out
53 dropped because of missing route
22 reassemblies required
11 packets reassembled ok
Icmp:
38023 ICMP messages received
7619 input ICMP message failed.
ICMP input histogram:
destination unreachable: 23947
timeout in transit: 129
I don't know if the upstream developers of ss intend on expanding the available output from the command, but near as I can tell... ss doesn't offer anything equivalent to the netstat -s statistics.
/ SenseiC bows out
the netstat command has been deprecated in favor of the faster, more human-readable ss command. See recommendations from RHEL 7, Debian, and Arch Linux regarding the deprecation of net-tools, including netstat, with iproute alternatives, specifically ss.
The ss command is a tool used to dump socket statistics and displays information in similar fashion (although simpler and faster) to netstat.
$ ss
is replacing netstat. You can use it like this:
$ ss -aunp | grep radi
I use "show sockets":
sudo ss -ltpn
This command also shows the associated processes:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:* users:(("rpcbind",pid=844,fd=8))
LISTEN 0 100 0.0.0.0:8080 0.0.0.0:* users:(("java",pid=1554,fd=60))
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=1048,fd=13))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1891,fd=3))
LISTEN 0 1 127.0.0.1:8005 0.0.0.0:* users:(("java",pid=1554,fd=76))
Swap -t with -u for UDP instead of TCP.
In the beginning I always used -ltpan, but sometimes that shows a bit much.
ss -h (help on Ubuntu 18.04):
Usage: ss [ OPTIONS ]
ss [ OPTIONS ] [ FILTER ]
-h, --help this message
-V, --version output version information
-n, --numeric don't resolve service names
-r, --resolve resolve host names
-a, --all display all sockets
-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
-i, --info show internal TCP information
-s, --summary show socket usage summary
-b, --bpf show bpf filter socket information
-E, --events continually display sockets as they are destroyed
-Z, --context display process SELinux security contexts
-z, --contexts display process and socket SELinux security contexts
-N, --net switch to the specified network namespace name
-4, --ipv4 display only IP version 4 sockets
-6, --ipv6 display only IP version 6 sockets
-0, --packet display PACKET sockets
-t, --tcp display only TCP sockets
-S, --sctp display only SCTP sockets
-u, --udp display only UDP sockets
-d, --dccp display only DCCP sockets
-w, --raw display only RAW sockets
-x, --unix display only Unix domain sockets
--vsock display only vsock sockets
-f, --family=FAMILY display sockets of type FAMILY
FAMILY := {inet|inet6|link|unix|netlink|vsock|help}
-K, --kill forcibly close sockets, display what was closed
-H, --no-header Suppress header line
-A, --query=QUERY, --socket=QUERY
QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram}[,QUERY]
-D, --diag=FILE Dump raw information about TCP sockets to FILE
-F, --filter=FILE read filter information from FILE
FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
STATE-FILTER := {all|connected|synchronized|bucket|big|TCP-STATES}
TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listening|closing}
connected := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
synchronized := {established|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
bucket := {syn-recv|time-wait}
big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listening|closing}