Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of lsof -i output

Tags:

lsof

I have run the command

 sudo lsof -i tcp:46265

Output

COMMAND   PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
mysqld   4580 mysql   30u  IPv4 70185524      0t0  TCP localhost:mysql->localhost:46265 (ESTABLISHED)
java    53105  root   54u  IPv6 70185523      0t0  TCP localhost:46265->localhost:mysql (ESTABLISHED)

Can someone explain what localhost:mysql->localhost:46265 and localhost:46265->localhost:mysql mean ?

like image 817
Ravi Avatar asked Jan 12 '23 03:01

Ravi


1 Answers

If there is an established TCP connection, lsof actually displays TCP socket data. If two local processes communicate with each other via TCP, there is an open socket in each. The first HOST:PORT shows the process' own socket and after the -> the connected remote socket is shown in the other process.

For known standard ports, the numbers are replaced with names.

When you establish a TCP connection with a server, your client program uses a random source port number. That's 46265.

The format is:

PROCESS    OTHER
HOST:PORT->HOST:PORT
like image 132
SzG Avatar answered Feb 09 '23 07:02

SzG