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?
Contents
- 1 What are Linux Networking Ports?
- 2 Types of Linux Transport Protocols
- 3 Common Networking Ports in Linux
- 4 How to Check if a Port is in Use on Linux
- 5 How to Check if a Port is Open on Linux?
- 6 How to Check if a Port is Closed on Linux?
- 7 Wrapping Up: Linux Ports and RunCloud
- 8 FAQ on Linux Ports
- 8.1 How do I get a list of all ports?
- 8.2 How to check port connectivity in Linux?
- 8.3 How do I know if port 443 is open in Linux?
- 8.4 How to list all open ports in Linux using netstat?
- 8.5 How many ports does Linux have?
- 8.6 Can you ping a port?
- 8.7 Is port 22 SSH or SFTP?
- 8.8 What is port 80 in Linux?
- 8.9 What port is SFTP?
- 8.10 What port is FTP?
- 8.11
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.
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux.png)
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:
- 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.
- 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.
- 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.
- 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.
- 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:
netstat
: Running the command without any options will display a list of open sockets.netstat -a
: This will display all connections and listening ports.netstat -t
: Displays only TCP connections.netstat -u
: Used to display only UDP connections.netstat -n
: Shows numerical addresses instead of trying to determine symbolic host, port or user names.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.netstat -r
: This command is used to display the routing table.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).
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux-1.png)
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:
ss
: Running the command without any options will display a list of open sockets.ss -a
: This command will display all active (listening and non-listening) sockets.ss -t
: Display only TCP sockets.ss -u
: Used to display only UDP sockets.ss -n
: Shows numerical addresses instead of trying to determine symbolic host, port or user names.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.
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux-2.png)
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.
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux-3.png)
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.
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux-4.png)
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?
![](https://linuxpunx.com/wp-content/uploads/2024/07/how-to-check-if-tcp-port-is-open-closed-or-in-use-on-linux-5.png)
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.