When working with networking services, you might encounter networking ports on Linux. But have you ever wondered what these ports are?

In this post, we will explain everything you need to know about networking ports in Linux, including how different networking protocols (TCP and UDP) use these ports. We will also show you how to check if a TCP port is open, closed or in use on Linux.

Let’s get started!

What are Linux Networking Ports?

In Linux, a networking port is an interface for a software application to share data across devices over a network. While the IP address is used to identify the host in a network, the port number identifies a specific process or service running on that host. These ports are identified by port numbers, which range from 0 to 65,535 and are integral to how Linux machines communicate with other machines on the network.

Let’s try to understand it with the help of an example: think of a Linux machine as a large apartment building, and each apartment in the building is a software application. Now, just like each apartment has a unique mailbox for receiving mail, each software application has a unique networking port for receiving data.

The mailman (network router) knows which mailbox (port) to deliver the mail (data) to by looking at the mailbox number (port number). Similarly, data knows which software application to go to by looking at the port number.

For example, in your RunCloud server, think of SSH, HTTP, and HTTPS as different apartments – port 22 is the mailbox for SSH, port 80 is for HTTP, and port 443 is for HTTPS. When data arrives, it knows which ‘apartment’ to go to based on these ‘mailbox numbers’.

In much the same way that you can open, close, or check your mailbox, RunCloud allows you to manage these ‘mailboxes’ (ports) from the Security tab. You can also configure firewall settings to open a port to allow data in, or close a port to deny data.

Types of Linux Transport Protocols

Let’s continue with our apartment building analogy to explain the difference between UDP and TCP in the context of networking ports.

UDP (User Datagram Protocol) is like a postman who delivers mail without waiting for you to confirm that you’ve received it – he simply drops the mail in your mailbox (port) and moves on. This makes UDP fast and efficient, but there’s no guarantee that the mail (data) will be received.

TCP (Transmission Control Protocol), on the other hand, is like a courier service that requires you to sign for a package – the courier (TCP) establishes a connection with you (the software application), ensures you’re available to receive the package (data), and only then delivers it. This makes TCP reliable, but slower than UDP due to the time taken to establish the connection.

Although TCP and UDP are different technologies, they can both be used for sending data over a network, and since they both have different advantages and disadvantages, they are often used simultaneously for different purposes.

Common Networking Ports in Linux

If you’re creating a networking application on Linux, then you’ll need to use a port to receive data. However, only one single program can listen to a port at one time – if you try to use a port which is already in use, you’ll get an error message.

In this section, we’ll list a few well-known port numbers, which range from 0 to 1023 and are standardized across all operating systems as well as software applications. Here are some common networking ports used in Linux:

  1. Port 21 – File Transfer Protocol (FTP): FTP uses this port for transferring files between systems. For example, you might use FTP to upload a website’s files to its hosting server.
  2. Port 22 – Secure Shell (SSH): SSH is used for secure remote administration of systems. For example, a system administrator may use SSH to log in to a web server located in a different geographical location.
  3. Port 80 – Hypertext Transfer Protocol (HTTP): This port is used by web servers for non-encrypted communication. When you access a website using http://, your browser communicates with the web server on port 80.
  4. Port 443 – HTTP Secure (HTTPS): Port 443 is used for secure web communication encrypted with SSL/TLS. When you access a website using https://, your browser communicates with the web server on port 443.
  5. Port 3306 – MySQL Database System: MySQL, a popular database management system, listens on this port. Applications connect to this port to communicate with the database.

To learn more about this, you can refer to the Internet Assigned Numbers Authority’s list of registered port numbers and protocols used by each application.

How to Check if a Port is in Use on Linux

On Linux, you can use built-in utility tools to check if a port is in use – let’s see how:

Using the netstat Command

In Linux, netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interfaces. It’s used for finding problems in the network, and to determine the amount of traffic on the network as a performance measurement.

Here’s a brief overview of some common uses of the netstat command:

  1. netstat: Running the command without any options will display a list of open sockets.
  2. netstat -a: This will display all connections and listening ports.
  3. netstat -t: Displays only TCP connections.
  4. netstat -u: Used to display only UDP connections.
  5. netstat -n: Shows numerical addresses instead of trying to determine symbolic host, port or user names.
  6. netstat -s: Shows statistics by protocol. By default, statistics are shown for TCP, UDP and IP; The -p option may be used to specify a subset of the default.
  7. netstat -r: This command is used to display the routing table.
  8. netstat -i: You can display the interfaces that are being used for network connections using this command.

For example, if you want to check whether a service is running and listening on the expected ports, you might use netstat -tuln. This will list all TCP (-t) and UDP (-u) connections that are currently listening (-l) and display all addresses as numbers (-n).

Using the ss Command

In Linux, ss (socket statistics) is a command-line tool used to view socket statistics and other network information similar to netstat. Here’s a brief overview of some common uses of the ss command:

  1. ss: Running the command without any options will display a list of open sockets.
  2. ss -a: This command will display all active (listening and non-listening) sockets.
  3. ss -t: Display only TCP sockets.
  4. ss -u: Used to display only UDP sockets.
  5. ss -n: Shows numerical addresses instead of trying to determine symbolic host, port or user names.
  6. ss -l: Display only the listening sockets.

For example, if you want to check whether a service is running and listening on the expected ports, you might use ss -tuln. This will list all TCP (-t) and UDP (-u) connections that are currently listening (-l) and display all addresses as numbers (-n).

To check whether a specific port is listening, you can use the grep command in combination with ss. For example, ss -tuln | grep :<your-port-number>. Replace <your-port-number> with the port number you want to check. This command will filter out the output of the ss command to only show lines that include your specified port number.

How to Check if a Port is Open on Linux?

On Linux, nc (netcat) is a versatile command-line tool that can read and write data across network connections using TCP or UDP protocols, and it is often referred to as the “Swiss-army knife” for TCP/IP networking. To check whether a port is open or closed on your computer, you can use the following command:

nc -zv <your-ip-address> <your-port-number>

Here’s what each part does:

  • -z: This flag tells nc to scan for listening daemons, without sending any data to them.
  • -v: This flag makes nc give more verbose output – it will tell you more about what’s going on.
  • <your-ip-address>: This is the IP address of the machine you want to check the port on. You can replace this with localhost to check your own machine.
  • <your-port-number>: This is the port number you’re checking.

For example, if you want to check whether a web server is running on your own machine, you might use nc -zv localhost 80. If the port is open, nc will return a success message such as localhost [127.0.0.1] 80 (http) open. If the port is closed, it will return a failure message.

To check whether a port is open on a remote machine, you can replace localhost with the IP address of the remote machine. For example, nc -zv 1.1.1.1 53 will check if port 53 is open on the machine with IP address 1.1.1.1.

How to Check if a Port is Closed on Linux?

If a port is not in use or not open, it is closed. You can verify whether a port is open by using the nc command as described above – if the port is closed, the command will return a failure message.

Wrapping Up: Linux Ports and RunCloud

Managing ports is a crucial aspect of Linux system administration and checking which ports are open, closed, or in use can help maintain the security and efficiency of your system. We strongly recommend you close unnecessary ports and only keep those open that are required by your applications.

RunCloud simplifies this process by providing a user-friendly dashboard that allows you to manage your Linux server and networking with just a few clicks.

If you’re looking for a way to make managing your Linux server and its ports easier, consider signing up for RunCloud. It’s designed to streamline server management, making it a valuable tool for any Linux user. Don’t miss out on this opportunity to enhance your Linux experience. Sign up for RunCloud today!

FAQ on Linux Ports

How do I get a list of all ports?

The Internet Assigned Numbers Authority maintains a port registry that ranges from 0-65,535. If you want to get a list of all ports which are currently in-use, then you can use the following netstat command on your Linux server.
sudo netstat -plnt

How to check port connectivity in Linux?

To check port connectivity in Linux, you can use the nc (netcat) command as follows: nc -zv  
Replace  and  with your IP address and the port number you want to check, respectively.

How do I know if port 443 is open in Linux?

To check if port 443 is open on Linux, you can use the nc (netcat) command as follows: nc -zv localhost 443

How to list all open ports in Linux using netstat?

To list all open ports in Linux using netstat, you can use the following command:
netstat -tuln
This command will list all TCP and UDP ports that are being listened to.

How many ports does Linux have?

Linux has a total of 65,536 ports, ranging from 0 to 65,535.

Can you ping a port?

While the term “ping a port” is not technically accurate, you can check if a specific port is open using the telnet or nc (netcat) command.

Is port 22 SSH or SFTP?

Port 22 is used for both SSH and SFTP – SFTP operates over port 22, using the underlying Secure Shell (SSH) protocol to establish a secure and encrypted connection for secure file transfers.

What is port 80 in Linux?

Port 80 in Linux is typically used for HTTP (Hypertext Transfer Protocol), which is used for transmitting hypertext over the internet.

What port is SFTP?

SFTP uses port 22, the same as SSH.

What port is FTP?

FTP (File Transfer Protocol) typically uses port 21 for control commands and port 20 for data transfer.