Administration CentOS Fedora FreeBSD Linux Tips and Tricks

Identify the process that is using some specific port

Sometimes, you may encounter a situation where you see some ports being used by some service, but you cannot exactly determine which application/service is using it. This article talks about how to identifying such services.


FreeBSD

In the case of FreeBSD, you can use “lsof” command to determine the service that is reserving port as below.

lsof -i :199
COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
snmpd   993 root    9u  IPv4 0xfffff800037d3c00      0t0  TCP *:smux (LISTEN)

Here I am trying to find out which service is using port 119.

Also you can use “sockstat” to identify the service that is using the port. Here -4 says to list only IPV4 addresses.

sockstat -4 -p 199
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
root     snmpd      993   9  tcp4   *:199                 *:*

Linux

In the case of Linux, you can use “netstat” command with options as shown in the following example. Here I am trying to find out which service is using port 3306.

netstat -nlp|grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                 LISTEN      4248/mysqld

You can use “lsof” command as well :

lsof -i :3306|grep LISTEN
mysqld  4248 mysql   15u  IPv4    11420      0t0  TCP *:mysql (LISTEN)

Related Articles

  • How to clear the YUM cache?

    What is yum? The Yellowdog Updater, Modified (yum) is an open-source command-line package-management utility for Linux operating systems using the RPM Package Manager. Yum allows automatic updates, package and dependency...
  • Media tools installation Error/Fix

    While installing media tools like Neroacc, we might come across the following errors   ERROR: ====== /usr/ports/audio/linux-neroaaccodec]# make install clean ===>  Staging for linux-neroaaccodec-1.5.1 ===>   linux-neroaaccodec-1.5.1 depends on file: /compat/linux/etc/redhat-release...
  • Add IP to CentOS 5/6

    If you recently got a secondary IP block for your server but you do not know how to bind the secondary IP address, please follow the steps below:   First, run...
  • SSL Certificate Installation for Courier IMAP and POP

    This guide will provide you information on how to setup and configure SSL certificates for the courier IMAP mail server.   Prior to the installation you will need to purchase...