Languages
[Edit]
EN

Linux - list all connected tcp clients

2 points
Created by:
AnnLen
1771

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.
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.