Which ports are being used?
Netstat is a tool to get an overview of network connections and interfaces.
You can get a detailed list of ports being used of what connections with the netstat command and the following five flags. Read more about the flags in the manual $ man netstat
.
$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 833/sendmail: MTA:
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 634/nrpe
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 338/mongod
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 612/mysqld
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN 833/sendmail: MTA:
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 264/portmap
tcp 0 0 109.202.159.44:80 0.0.0.0:* LISTEN 1827/node
tcp 0 0 127.0.0.1:28017 0.0.0.0:* LISTEN 338/mongod
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 790/sshd
tcp6 0 0 :::22 :::* LISTEN 790/sshd
udp 0 0 0.0.0.0:111 0.0.0.0:* 264/portmap
If you only want to know what is listening on a specific port you can just grep that port. In this example port 22 (sshd):
$ netstat -tulpn | grep ':22'