Languages
[Edit]
EN

Linux - list all connected tcp clients

2 points
Created by:
Mark-Rotteveel
537

In this article, we're going to have a look at how to print connected tcp/tcp6 clients and their ip adresses with netstat command under Bash in Linux.

1. Simple console print example

Type in terminal:

netstat -tn

Where:

  • -t means tcp connections only,
  • -n show numerical addresses.

Becasue: netstat -tn is equivalent to netstat -t -n

Console print:

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp6       0      0 83.145.210.81:80         172.69.134.86:45022     ESTABLISHED
tcp6       0      0 83.145.210.81:80         172.69.134.224:50256    TIME_WAIT
tcp6       0      0 83.145.210.81:80         172.69.134.230:13386    TIME_WAIT
tcp6       0      0 83.145.210.81:80         162.158.167.193:27216   TIME_WAIT
tcp6       0      0 83.145.210.81:80         162.158.154.66:17908    ESTABLISHED
tcp6       0      0 83.145.210.81:80         141.101.104.246:45062   ESTABLISHED
tcp6       0      0 83.145.210.81:80         162.158.88.25:25148     ESTABLISHED
tcp6       0      0 83.145.210.81:80         172.68.244.11:48602     ESTABLISHED
tcp6       0    463 83.145.210.81:80         162.158.167.7:63428     ESTABLISHED
tcp6       0      0 83.145.210.81:80         172.69.134.122:56144    TIME_WAIT
tcp6       0      0 83.145.210.81:80         162.158.165.233:17370   TIME_WAIT
tcp6       0      0 83.145.210.81:80         172.69.134.224:39788    TIME_WAIT
tcp6       0      0 83.145.210.81:80         162.158.166.218:64254   TIME_WAIT

Where:

  • Foreign Address - shows ip addresses for connected clients

Note: as we can see in console print, there are connected only tcp6 clients.

2. Other netstats useful variants

If we would like remove errors we can redirect stderr (standard error output) to null dev (place where unnecessary things "vanish") with following command:

netstat -tn 2>/dev/null

Where:

  • 2> redirects error output to other place.

If we would like to make print scrollable following command will be useful:

netstat -tn 2>/dev/null | less

Where:

  • | redirects ouput from one program to another one,
  • less displays results in scrollable form.

Alternative titles

  1. Linux - how to list all connected tcp clients?
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Linux

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join