- Linux find out which port is open using the command line
- Linux find out which port is open using the command line
- Linux find port open command
- How to find out and list of all open TCP/UDP ports in Linux
- fuser command examples to find out which port is open
- How to use lsof command to display open port on Linux
- Conclusion
- How to check if port is in use on Linux or Unix
- How to check if port is in use in
- Option #1: lsof command
- Option #2: netstat command
- Linux netstat syntax
- FreeBSD/MacOS X netstat syntax
- OpenBSD netstat syntax
- Option #3: nmap command
- A note about Windows users
- Conclusion
- How to Find Out List of All Open Ports in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to Check Open Ports in Linux
- 1) Check open ports using ss command
- 2) Check open ports using netstat command
- 3) Check open ports using the lsof command
- 4) Check open ports using the Nmap utility
- Wrapping up
Linux find out which port is open using the command line
Linux find out which port is open using the command line
The procedure to list open ports in Linux is as follows:
- Open the terminal application
- Use command netstat -tulpn to open ports
- Another option is to run ss -tulpn to open ports on modern Linux distros
Let us see all commands in details.
Linux find port open command
One can use the netstat command or ss command find out which process is listing upon a port:
$ sudo netstat -tulpn
$ sudo netstat -tulpn | more
$ sudo netstat -tulpn | grep ‘:port’
$ sudo netstat -tulpn | grep ‘:22’
OR
$ sudo ss -tulpn
$ sudo ss -tulpn | more
$ sudo ss -tulpn | grep ‘:port’
$ sudo ss -tulpn | grep ‘:22’
Click to enlarge image
How to find out and list of all open TCP/UDP ports in Linux
Other commands that you can use are as follows.
fuser command examples to find out which port is open
One can list the processes PID that opened tcp port 22, enter:
$ sudo fuser 22/tcp
Sample outputs:
Let us see process name associated with PID # 1462, execute:
$ sudo ls -l /proc/1462/exe
Outputs:
/usr/sbin/sshd has opened tcp port 22. But, what is sshd? Let us find out:
$ whatis sshd
Example outputs:
How to use lsof command to display open port on Linux
$ sudo lsof -i :portNumber
$ sudo lsof -i tcp:portNumber
$ sudo lsof -i udp:portNumber
$ sudo lsof -i :22
$ sudo lsof -i :22 | grep LISTEN
Click to enlarge file
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Conclusion
You just learned how to list open ports on a Linux based system. For more info see man pages.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to check if port is in use on Linux or Unix
H ow do I determine if a port is in use under Linux or Unix-like system? How can I verify which ports are listening on Linux server? How do I check if port is in use on Linux operating system using the CLI?
It is important you verify which ports are listening on the server’s network interfaces. You need to pay attention to open ports to detect an intrusion. Apart from an intrusion, for troubleshooting purposes, it may be necessary to check if a port is already in use by a different application on your servers. For example, you may install Apache and Nginx server on the same system. So it is necessary to know if Apache or Nginx is using TCP port # 80/443. This quick tutorial provides steps to use the netstat, nmap and lsof command to check the ports in use and view the application that is utilizing the port.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | lsof, ss, and netstat on Linux |
Est. reading time | 3 minutes |
How to check if port is in use in
To check the listening ports and applications on Linux:
- Open a terminal application i.e. shell prompt.
- Run any one of the following command on Linux to see open ports:
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here - For the latest version of Linux use the ss command. For example, ss -tulw
Let us see commands and its output in details.
Option #1: lsof command
The syntax is:
$ sudo lsof -i -P -n
$ sudo lsof -i -P -n | grep LISTEN
$ doas lsof -i -P -n | grep LISTEN ### [OpenBSD] ###
Sample outputs:
Fig.01: Check the listening ports and applications with lsof command
Option #2: netstat command
You can check the listening ports and applications with netstat as follows.
Linux netstat syntax
Run netstat command along with grep command to filter out port in LISTEN state:
$ netstat -tulpn | grep LISTEN
The netstat command deprecated for some time on Linux. Therefore, you need to use the ss command as follows:
sudo ss -tulw
sudo ss -tulwn
sudo ss -tulwn | grep LISTEN
Where, ss command options are as follows:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
- -t : Show only TCP sockets on Linux
- -u : Display only UDP sockets on Linux
- -l : Show listening sockets. For example, TCP port 22 is opened by SSHD server.
- -p : List process name that opened sockets
- -n : Don’t resolve service names i.e. don’t use DNS
FreeBSD/MacOS X netstat syntax
$ netstat -anp tcp | grep LISTEN
$ netstat -anp udp | grep LISTEN
OpenBSD netstat syntax
$ netstat -na -f inet | grep LISTEN
$ netstat -nat | grep LISTEN
Option #3: nmap command
The syntax is:
$ sudo nmap -sT -O localhost
$ sudo nmap -sU -O 192.168.2.13 ##[ list open UDP ports ]##
$ sudo nmap -sT -O 192.168.2.13 ##[ list open TCP ports ]##
Sample outputs:
Fig.02: Determines which ports are listening for TCP connections using nmap
A note about Windows users
You can check port usage from Windows operating system using following command:
netstat -bano | more
netstat -bano | grep LISTENING
netstat -bano | findstr /R /C:»[LISTEING]»
Conclusion
This page explained command to determining if a port is in use on Linux or Unix-like server. For more information see the nmap command and lsof command page online here
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to Find Out List of All Open Ports in Linux
In this article, we will briefly talk about ports in computer networking and move to how you can list all open ports in Linux.
In computer networking, and more definitely in software terms, a port is a logical entity which acts as a endpoint of communication to identify a given application or process on an Linux operating system. It is a 16-bit number (0 to 65535) which differentiates one application from another on end systems.
The two most popular Internet transport protocols, Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) and other less known protocols use port numbers for communication sessions (source and destination port numbers in conjunction with the source and destination IP addresses).
In addition, a combination of an IP address, port and protocol such as TCP/UDP is known as a socket, and every service must have a unique socket.
Below are the different categories of ports:
- 0-1023 – the Well Known Ports, also referred to as System Ports.
- 1024-49151 – the Registered Ports, also known as User Ports.
- 49152-65535 – the Dynamic Ports, also referred to as the Private Ports.
You can view a list of different applications and port/protocol combination in /etc/services file in Linux using cat command:
To list all open ports or currently running ports including TCP and UDP in Linux, we will use netstat, is a powerful tool for monitoring network connections and statistics.
- -l – prints only listening sockets
- -n – shows port number
- -t – enables listing of tcp ports
- -u – enables listing of udp ports
You can also use ss command, a well known useful utility for examining sockets in a Linux system. Run the command below to list all your open TCP and UCP ports:
Make it a point to read through the man pages of the commands above for more usage information.
In summary, understanding the concept of ports in computer networking is very vital for system and network administrators. You can as well go through this netstat guide with simple, precise and well explained examples.
Last but not least, get in touch with us by sharing other methods for listing open ports in Linux or asking a question via the response form below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to Check Open Ports in Linux
During the troubleshooting of services running on a Linux system, checking open ports is one of the tasks any user or administrator should consider performing. If a service is expected to be running but for some reason it’s not, then most likely the port associated with that service is closed and should be opened.
In this tutorial, we will demonstrate how to check open ports in a Linux from the command line.
1) Check open ports using ss command
The Linux ss command gives you detailed insights on open ports and listening sockets. It draws information from the Linux kernel and is more preferred to the netstat command which has been deprecated.
To display listening TCP connections, run the command
Sample output
l — Shows listening sockets
t — Stands for TCP port
To display listening UDP connections, issue the command
Sample output
u — Stands for UDP port
To display both tcp and udp, process name
p — List process name that opened sockets
To print out all socket connections, simply use the ss command in its default format
Sample output
2) Check open ports using netstat command
The netstat command is a powerful command tool that is used for checking open TCP and UDP ports alongside other attributes. To check open ports, issue the command:
Sample output
Let’s take a closer look at the command options:
p — Displays the Procees ID associated with a service or Program name
n — Displays the numerical number of the port running e.g 3306 for mysqld, and 22 for sshd.
l — Shows listening sockets
t — Displays TCP connections
u — Displays UDP connections
3) Check open ports using the lsof command
The lsof command is a network command tool that can also be used to check open ports in a Linux system. To display open ports, issue the command
Sample output
If you wish to display open sockets, use the lsof command and pipe the output to grep as shown:
Sample output
To view all TCP connections execute :
Sample output
To display all UDP connections run the command:
Sample output
4) Check open ports using the Nmap utility
Nmap is a free and opensource network scanning tool usually used for reconnaissance in ethical hacking for discovering open ports of remote systems. By default, Nmap does not come installed on your system. To install Nmap, issue the command
To scan for open TCP ports, run the command
Sample output
To scan for open UDP ports, run the command:
Sample output
Wrapping up
Those are the linux commands and tools used for port scanning to check open ports in a Linux system. As always, your feedback is most welcome. If you have other ideas on how to check open ports, do get in touch with us.
Источник