poniedziałek, 2 lipca 2012

How to check linux ports

So here's quick tip. How to find out what process has which port. First logon root and to open list port use :
lsof -i
or use netstat
netstat -tulpn

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:1551            0.0.0.0:*               LISTEN      2443/sh         
tcp        0      0 0.0.0.0:1553            0.0.0.0:*               LISTEN      2445/kadu       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1739/cupsd      
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1261/postgres   
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1687/master     
tcp        0      0 0.0.0.0:9306            0.0.0.0:*               LISTEN      1201/searchd    
tcp        0      0 0.0.0.0:9312            0.0.0.0:*               LISTEN      1201/searchd    
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1232/mysqld     

To se what processs is bound to let say 3305:
root@work:~# lsof -i :3306

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  1250 mysql   10u  IPv4   5421      0t0  TCP localhost:mysql (LISTEN)
Now let's take a closer look at proces id (PID)
root@work:~# ls -l /proc/1250/exe
lrwxrwxrwx 1 root root 0 2012-06-25 19:18 /proc/1250/exe -> /usr/sbin/mysqld
And that's all ; )

Brak komentarzy:

Prześlij komentarz