Listening for Programs on Server Ports

On a Linux or Unix dedicated server, applications that access the Internet must do so using ports. Think of a port, as the name implies, as a window to the outside world. Without a port, a program will not have outside access, and outside computers will not have access into your server.

When configuring programs or troubleshooting connection problems, it is important to know what ports your program is using. With the combination of a few simple command line tools, you can do just that.

First, use netstat to find out what ports are currently in use:

# netstat -tulpn

The output will look like this:

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:3306 0.0.0.0:* LISTEN 1125/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 567/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7842/apache2

To filter the results for only the port you need, enter:

# netstat -tulpn | grep :80

This example would show only the processes running on port 80 (in this case, your web server).

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1237/apache2

If you know exactly what port you need information about, you can use the fuser command for a more direct approach.

# fuser 7000/tcp

This outputs the PID (process identifier):

7000/tcp: 4028

To find out what program is using that PID, type:

# ls -l /proc/4028/exe

The output would appear as:

lrwxrwxrwx 1 serv serv 0 2010-10-29 11:00 /proc/4028/exe -> /usr/bin/tomato

If you are unsure what tomato is, you can type “man tomato” to find out.

There is much more you can learn about processes in addition to their corresponding ports. In the coming weeks, we will cover some more helpful process management tips.











Comments: