Temos várias opções:
-
netstat
-
fuser
-
lsof
netstat
sudo netstat -nlp
dará a você todas as conexões de rede abertas.
$ netstat -nlp
(No info could be read for "-p": geteuid()=901743 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:44886 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8139 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:81 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:48562 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::46871 :::* LISTEN -
tcp6 0 0 ::1:6010 :::* LISTEN -
tcp6 0 0 :::57179 :::* LISTEN -
tcp6 0 0 :::5666 :::* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::4949 :::* LISTEN -
udp 0 0 127.0.0.1:896 0.0.0.0:* -
udp 0 0 0.0.0.0:45467 0.0.0.0:* -
udp 0 0 0.0.0.0:111 0.0.0.0:* -
udp 0 0 10.105.2.3:123 0.0.0.0:* -
udp 0 0 127.0.0.1:123 0.0.0.0:* -
udp 0 0 0.0.0.0:123 0.0.0.0:* -
udp 0 0 0.0.0.0:39554 0.0.0.0:* -
udp 0 0 0.0.0.0:711 0.0.0.0:* -
udp 0 0 0.0.0.0:10000 0.0.0.0:* -
udp6 0 0 :::53766 :::* -
udp6 0 0 :::49696 :::* -
udp6 0 0 :::111 :::* -
udp6 0 0 fe80::5054:ff:fed0::123 :::* -
udp6 0 0 ::1:123 :::* -
udp6 0 0 :::123 :::* -
udp6 0 0 :::711 :::* -
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 7943 - /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 8494 - /run/rpcbind.sock
unix 2 [ ACC ] STREAM LISTENING 729659 - /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 11324 - /var/run/php5-fpm.sock
unix 2 [ ACC ] STREAM LISTENING 11082 - /var/run/nscd/socket
unix 2 [ ACC ] STREAM LISTENING 7607 - @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 668784 - /var/run/nslcd/socket
unix 2 [ ACC ] SEQPACKET LISTENING 6768 - /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 8924 - /var/run/acpid.socket
lsof
lsof -i tcp:43796
lhe dará a lista de processos usando a porta tcp 43796.
$ lsof -i tcp:1723
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
pptpd 2870 root 6u IPv4 17638 0t0 TCP *:1723 (LISTEN)
fuser
fuser 43796/tcp
lhe dará a lista de pids usando a porta tcp 43796.
$ fuser 1723/tcp
1723/tcp: 2870