how to use netstat on a specific port in Linux

92,505

Solution 1

You can use

netstat -pnlt | grep ':portno'

another option , you can use nmap tool for checking open ports on the server

nmap -sT -O localhost

Output

Starting nmap 3.55 ( http://www.insecure.org/nmap/ ) at 2004-09-24 13:49 EDT
Interesting ports on localhost.localdomain (127.0.0.1):
(The 1653 ports scanned but not shown below are in state: closed)
PORT      STATE SERVICE
22/tcp    open  ssh 
25/tcp    open  smtp
111/tcp   open  rpcbind
Device type: general purpose

Netstat Example :

[root@krizna ~]# netstat -pnlt | grep ':80'
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name 
tcp        0      0 :::80                       :::*                        LISTEN      1164/httpd          

Solution 2

I think netstat -nat | grep port | grep LISTEN should do the trick.

Solution 3

use netstat -anp | grep portNumber

Share:
92,505

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    Guys i want to know if my specific port is running a server using netstat? how do i achieve that?

    • rags
      rags about 11 years
      netstat -anp | grep portNumber
  • Admin
    Admin about 11 years
    so im getting list of many port 80 connections. how do i find the server port?
  • Admin
    Admin about 11 years
    and what part there in the results i can determine if it is a server?
  • Admin
    Admin about 11 years
    Check the netstat example part, port :::80 is shown under local address which is LISTENING ( i mean open ).
  • Paul Tobias
    Paul Tobias about 8 years
    This is listing all ports, and then grep for listening ports. Instead it should just show the listening ports with -l instead of -a. And the question was not only about tcp ports so the -t option shouldn't be there.
  • Kevin Keane
    Kevin Keane almost 6 years
    It is worth mentioning that the grep ':portno' may also pick up some IPv6 addresses that happen to contain that sequence. That can be a problem if you try to use this command in a script.