52

In linux, netstat command tells us information of active sockets in system.

I understand that netstat uses /proc/net/tcp to acquire the system network information.

Since netstat man page says that netstat is obsolete, so we should use 'ss'.

NOTE
   This program is 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.

I have discovered that ss performs similar functionality but it does not use /proc/net/tcp to acquire system network information.

Now I am curious how ss gets system network socket information?

radtek
  • 34,210
  • 11
  • 144
  • 111
daehee
  • 5,047
  • 7
  • 44
  • 70

5 Answers5

35

It gets them from kernel space directly using Netlink which uses the classic sockets API.

ggiroux
  • 6,544
  • 1
  • 22
  • 23
  • 1
    thank you, it would be better if there is more detailed information about how ss queries information to kernel space – daehee Aug 24 '12 at 17:59
25

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.

google doc screenshot

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

int_ua
  • 1,646
  • 2
  • 18
  • 32
21

ss is included in iproute2 package and is the substitute of the netstat. ss is used to dump socket statistics. It shows information similar to netstat. It can display more TCP and state information than other tools. It is a new, incredibly useful and faster (compared to netstat) tool for tracking TCP connections and sockets.

timlyo
  • 2,086
  • 1
  • 23
  • 35
Mr.Cool
  • 1,525
  • 10
  • 32
  • 51
11

Check out the source for ss:

https://github.com/shemminger/iproute2/blob/master/misc/ss.c

Basically it directly queries the kernel and can respond much faster than netstat.

tgogos
  • 23,218
  • 20
  • 96
  • 128
Mahesh Neelakanta
  • 1,472
  • 2
  • 11
  • 4
10

ss is a utility used to investigate sockets in Linux and Unix systems. It shows information similar to netstat and able to dump socket statistics.

But netstat cannot be replaced full by ss. Some netstat commands correspond better to ip command.

    $ netstat -r   replaced by  $ ip route
    $ netstat -i   replaced by  $ ip -s lin
    $ netstat -g   replaced by  $ ip maddr

I would say the "older" netstat command can be replaced with both ss and ip commands.

prosti
  • 42,291
  • 14
  • 186
  • 151