How to check open ports in Linux using the CLI

w‮‬ww.lautturi.com
How to check open ports in Linux using the CLI

To check the open ports on a Linux system using the command line, you can use the netstat command. This command displays a list of active network connections, including the local and remote addresses, the protocol, and the state of the connection.

To check the open ports on a Linux system, open a terminal window and run the following command:

netstat -tulpn

The -t option specifies that the netstat command should display information about TCP connections. The -u option specifies that the netstat command should display information about UDP connections. The -l option specifies that the netstat command should display only listening sockets, i.e., sockets that are waiting for incoming connections. The -p option specifies that the netstat command should display the name of the process associated with each socket. The -n option specifies that the netstat command should display numerical addresses instead of resolving hostnames.

The netstat command will display a list of active network connections, including the protocol (TCP or UDP), the local and remote addresses, the state of the connection, and the name of the process associated with each socket.

For example, the output might look something like this:

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      891/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1034/master
tcp6       0      0 :::80                   :::*                    LISTEN      1176/httpd
tcp6       0      0 :::22                   :::*                    LISTEN      891/sshd

In this example, the system has several active network connections, including an SSH server listening on port 22 (TCP), an email server listening on port 25 (TCP), and a web server listening on port 80 (TCP).

To check the open ports on a specific network interface, you can use the -i option with the netstat command.

For example, to check the open ports on the eth0 network interface, you can use the following command:

netstat -tulpn -i eth0

This will display a list of active network connections on the eth0 interface, including the protocol, the local and remote addresses, the state of the connection, and the name of the process associated with each socket.

Created Time:2017-10-28 21:38:59  Author:lautturi