Techolac - Computer Technology News
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
Techolac - Computer Technology News
No Result
View All Result
Home Linux

How do I check if a port is in use on Linux?

by Editorial Staff
December 31, 2020
in Linux
Reading Time: 4 mins read
” alt=”” border=”0″ data-src=”https://techolac.com/wp-content/uploads/2019/05/linux-logo.png” />

I am a new Linux system user. I need to find out which process is listening on a port on Linux using the command line. How do you find out which process is listening on a port on Linux operating systems?

A network port in Linux is nothing but a number that identifies one side of a connection between two systems. All networked devices use port numbers to determine to which process a message should be delivered. The domain name and IP address are like a street address, and port numbers are like room numbers.

Adblock detected 😱
My website is made possible by displaying online advertisements to my visitors. I get it! Ads are annoying but they help keep this website running. It is hard to keep the site running and producing new content when so many people block ads. Please consider donating money to the nixCraft via PayPal/Bitcoin, or become a supporter using Patreon.

 

Popular port numbers in Linux

  • HTTP – TCP 80
  • HTTPS – TCP 443
  • POP3 – TCP 110
  • SMTP – TCP 25
  • SSH – TCP 22
  • DNS/DOMAIN – TCP/UDP 53

Use the cat command or grep command/egrep command to query port numbers as follows:
cat /etc/services
grep -w 80 /etc/services
egrep -w '53/(tcp|udp)' /etc/services

” alt=”Find out which process is listening on a port on Linux” width=”599″ height=”211″ data-src=”https://techolac.com/wp-content/uploads/2019/05/Find-out-which-process-is-listening-on-a-port-on-Linux.png” data-srcset=”https://techolac.com/wp-content/uploads/2019/05/Find-out-which-process-is-listening-on-a-port-on-Linux.png 599w, https://techolac.com/wp-content/uploads/2019/05/1_Find-out-which-process-is-listening-on-a-port-on-Linux-300×106.png 300w” data-sizes=”(max-width: 599px) 85vw, 599px” />

How to check if a port is in use on Linux

The procedure is as follows:

  1. Open the terminal application
  2. Type any one of the followin command to check if a port is in use on Linux
    sudo lsof -i -P -n | grep LISTEN
    sudo netstat -tulpn | grep LISTEN
    sudo netstat -tulpn | grep :443
    sudo ss -tulpn | grep LISTEN
    sudo ss -tulpn | grep ':22'

Let us see some examples and sample commands in details.

See also  How to install htop on RHEL 8 using yum

How can you find out which process is listening on a port on Linux

Type the ss command or netstat command to see if a TCP port 443 is in use on Linux?
sudo netstat -tulpn | grep :443
sudo ss -tulpn | grep :443

If a port is open, you should see the output as follows:

tcp    0  0 0.0.0.0:443    0.0.0.0:*      LISTEN      438/nginx -g daemo

The port 443 is in use and opened by nginx service. Where,

  • -t : Display TCP sockets/port
  • -u : Show UDP sockets/port
  • -l : See only listening sockets i.e. open port
  • -p : Also display process name that opened port/socket
  • -n : View addresses and port numbers in numerical format. Do not use DNS to resolve names.

Getting a list of all open port in production

Simply run:
sudo lsof -i -P -n | grep LISTEN
sudo ss -tulpn
sudo netstat -tulpn

Sample outputs:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      500/redis-server 12
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      438/nginx -g daemon
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      407/lighttpd    
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      438/nginx -g daemon
tcp6       0      0 :::80                   :::*                    LISTEN      438/nginx -g daemon
udp        0      0 0.0.0.0:68              0.0.0.0:*                           277/dhclient

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 500/redis-server 12
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 438/nginx -g daemon
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 407/lighttpd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 438/nginx -g daemon
tcp6 0 0 :::80 :::* LISTEN 438/nginx -g daemon
udp 0 0 0.0.0.0:68 0.0.0.0:* 277/dhclient

Another outputs from the lsof command:

” alt=”Check if a port is in use on Linux” width=”599″ height=”372″ data-src=”https://techolac.com/wp-content/uploads/2019/05/Check-if-a-port-is-in-use-on-Linux.png” data-srcset=”https://techolac.com/wp-content/uploads/2019/05/Check-if-a-port-is-in-use-on-Linux.png 599w, https://techolac.com/wp-content/uploads/2019/05/1_Check-if-a-port-is-in-use-on-Linux-300×186.png 300w” data-sizes=”(max-width: 599px) 85vw, 599px” />
From the above outputs, it is clear that Lighttpd opened port TCP port 8080 and Nginx server opened TCP 80 and 443 ports. All of these servers run under a user named “www-data”.

Conclusion

You learned how to see if a port is in use on a Linux based machine using various command line utilities.

See also  How to Install VirtualBox and Extension Pack on Elementary OS 5.0 (Juno)

Related Posts

Top Commands to Check the Running Processes in Linux
Linux

Top Commands to Check the Running Processes in Linux

May 27, 2022
4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error
Linux

4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error

March 30, 2022
How Common Signals are Used in Kubernetes Pod Management
Linux

How Common Signals are Used in Kubernetes Pod Management

November 20, 2021

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Bitcoin Cloud Mining Sites

12 Best Bitcoin Cloud Mining Sites In 2022

August 9, 2022
Why did the Parag Parikh Long Term Equity Fund change its name to Parag Parikh Flexi Cap Fund?

Why did the Parag Parikh Long Term Equity Fund change its name to Parag Parikh Flexi Cap Fund?

August 9, 2022
Why Measuring Customer Experience Score Generate More Business Value?

Why Measuring Customer Experience Score Generate More Business Value?

August 9, 2022
The Key Phases for Successful Onboarding

The Key Phases for Successful Onboarding

August 9, 2022
30 ZiniTevi Alternatives To Watch Movies And TV Shows Online

30 ZiniTevi Alternatives To Watch Movies And TV Shows Online

August 8, 2022
  • DashTech
  • TechDaddy
  • Terms and Conditions
  • Disclaimer
  • Write for us

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

Go to mobile version