Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Wed Aug 23, 2017 8:50 am


System administration, processes administration, jobs, cron, resources, limits, shells, ssh, telnet.

Author Message
mandrei99
  Post  Post subject: How to check if ssh/http daemon listens on TCP port in FreeBSD using sockstat & lsof & netstat util  |  Posted: Mon Oct 17, 2011 9:27 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
 

How to check if ssh/http daemon listens on TCP port in FreeBSD using sockstat & lsof & netstat util

How to check if ssh/http daemon listens on TCP port in FreeBSD using sockstat & lsof & netstat utilities

As compared to Linux, FreeBSD "netstat" doesn't show the process ID, but instead, the "sockstat" utility does.

Checking SSH and Apache TCP ports in Linux and FreeBSD using lsof utility:
Code:
# lsof -Pni :22 -i :80
COMMAND   PID USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
httpd   17543  www    3u  IPv6 0xc35d3cb0      0t0  TCP *:80 (LISTEN)
sshd    61609 root    3u  IPv6 0xc35d3570      0t0  TCP *:22 (LISTEN)
sshd    61609 root    4u  IPv4 0xc35d3ae0      0t0  TCP *:22 (LISTEN)
httpd   75304 root    3u  IPv6 0xc35d3cb0      0t0  TCP *:80 (LISTEN)
httpd   78080  www    3u  IPv6 0xc35d3cb0      0t0  TCP *:80 (LISTEN)


Checking SSH and Apache TCP ports in FreeBSD using netstat:
Code:
# netstat -anf inet | grep -E "22|80"
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp46      0      0 *.80                   *.*                    LISTEN
tcp4       0      0 *.22                   *.*                    LISTEN


Checking SSH and Apache TCP ports in FreeBSD using sockstat:
Code:
# sockstat -4l  | grep -E ":22|:80"
www      httpd      56459 3  tcp4 6 *:80                  *:*
www      httpd      78080 3  tcp4 6 *:80                  *:*
www      httpd      18278 3  tcp4 6 *:80                  *:*
www      httpd      18046 3  tcp4 6 *:80                  *:*
www      httpd      18040 3  tcp4 6 *:80                  *:*
www      httpd      17815 3  tcp4 6 *:80                  *:*
www      httpd      17543 3  tcp4 6 *:80                  *:*
root     httpd      75304 3  tcp4 6 *:80                  *:*
root     inetd      72331 7  tcp4   *:222                 *:*
root     sshd       61609 4  tcp4   *:22                  *:*


Also, "sockstat" can show connected sockets if used with "-4c" instead.

Man sockstat:
Quote:
NAME
sockstat -- list open sockets

Synopsis
sockstat [-46clu] [-p ports] [-P protocols]

Description
The sockstat command lists open Internet or UNIX domain sockets.

The following options are available:

-4 Show AF_INET (IPv4) sockets.

-c Show connected sockets.

-l Show listening sockets.


"lsof" utility is not a base package in FreeBSD and it needs to be installed from ports (make install clean -C /usr/ports/sysutils/lsof) or from the online repository (pkg_add -rv lsof).





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "How to check if ssh/http daemon listens on TCP port in FreeBSD using sockstat & lsof & netstat util"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to check if ssh/http daemon listens on TCP port in Linux using lsof & netstat

mandrei99

0

5706

Mon Oct 17, 2011 9:17 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to identify each ethX device in Linux to what dual or quad port interface card it belongs to

mandrei99

0

717

Mon Jul 22, 2013 10:08 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to get UFS filesystem block size in FreeBSD

mandrei99

0

2035

Mon Jul 22, 2013 9:49 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to list PCI devices in FreeBSD - pciconf

mandrei99

0

7293

Mon Jul 22, 2013 9:58 am

mandrei99 View the latest post

There are no new unread posts for this topic. Squid clear cache on FreeBSD

mandrei99

0

1540

Mon Mar 03, 2014 7:37 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD - fuser checking processes that are using a filesystem

mandrei99

2

1188

Tue Mar 24, 2015 1:26 am

Woolmer View the latest post

There are no new unread posts for this topic. How to read UFS filesystem super block information in FreeBSD

mandrei99

0

1386

Mon Jul 22, 2013 9:52 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD slow booting: Recovering vi editor sessions

mandrei99

0

1262

Wed Feb 19, 2014 4:02 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to list the largest files in a directory in Linux/FreeBSD

mandrei99

0

540

Thu Jan 22, 2015 5:14 pm

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD - How to retrieve the newfs command that was used to create an existing UFS filesystem

mandrei99

0

683

Mon Jul 22, 2013 9:55 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO