1. Use the netstat command
netstat (network statistic) is a command-line tool that can be used to view network-related operating status, including network connections, routing tables, interface status, and more. In Ubuntu, you can use the following command to check the port usage:
$ netstat -tuln
The parameters of this command are explained as follows:
- -t: Indicates that only the connection of the TCP protocol is displayed
- -u: Indicates that only UDP protocol connections are displayed
- -l: Indicates that only the connections that are being listened to are displayed
- -n: Indicates that the domain name is not displayed, but the IP address is displayed directly
After the command is executed, it will output a result similar to the following:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN udp 0 0 127.0.0.53:53 0.0.0.0:* udp 0 0 0.0.0.0:68 0.0.0.0:* udp 0 0 0.0.0.0:5353 0.0.0.0:* udp6 0 0 :::5353