Replacing netstat sockets using ss
PLUG
2019Aug08
der.hans
https://floss.social/@FLOX_advocate
https://mastodon.social/@lufthans
This program is mostly obsolete. Replacement for netstat is ss.
Replacement for netstat -r is ip route. Replacement for netstat -i is
ip -s link. Replacement for netstat -g is ip maddr.
netstat - Print network connections, routing tables, interface statis-
tics, masquerade connections, and multicast memberships
By default, netstat displays a list of open sockets. If you don't
specify any address families, then the active sockets of all configured
address families will be printed.
polls /proc
displays socket information
faster with more capabilities
queries kernel space
part of iproute2 package in debian-based distributions
part of iproute-2 package in debian-based distributions
probably installed by default
ss
!= ssh
ss
When no option is used ss displays a list of open non-listening sockets
(e.g. TCP/UNIX/UDP) that have established connection.
ss -s
ss -l
ss -t
ss -tln
ss -uln
ss -tlnp
sudo ss -tlnp
ss -ant
ss -tn sport = :22
ss -to state established '( dport = :ssh or sport = :ssh )'
ss -tn '( dport = :ssh or sport = :ssh )'
ss -o state established '( dport = :https or dport = :http )'
ss -nt '( dst :443 or dst :80 )'
ss -nt dst :443 or dst :80
ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 192.168/16
ss -tan '( dport = :ssh or sport = :ssh )'
$ ss -to state established dport = :2222
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 127.0.0.1:53145 127.0.0.1:2222 timer:(keepalive,41min,0)
$ ss -tp sport = :53145
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 127.0.0.1:53145 127.0.0.1:2222 users:(("ssh",pid=16984,fd=3)
lufthans 16984 0.0 0.0 53468 5884 pts/1 S+ 21:12 0:00 ssh -p 2222 localhost
ss dst $cidr:$port
ss src $cidr:$port
$ ss dst 192.168/16:22
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp ESTAB 0 0 192.168.1.4:48538 192.168.1.14:ssh
tcp ESTAB 0 0 192.168.1.4:35830 192.168.1.15:ssh
ss -tn dport \> :1023
ss -tln -4
ss -tln -6
ss -x src /tmp/.X11-unix/*
ss -tn | wc -l
ss -an | wc -l