How to list and close open ports in linux

This guide will be demonstrating you how to get the status of the ports and to free up a port which is in use.
(Note : Following commands were tested on a ubuntu 11.10 installed pc)

List down all listening ports
netstat -lpn

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0                *                LISTEN      13098/java  
tcp        0      0              *                LISTEN      13098/java  
tcp        0      0              *                LISTEN      –          
tcp        0      0                  *                LISTEN      13098/java  
tcp        0      0                *                LISTEN      13098/java  
tcp        0      0                *                LISTEN      –          
tcp        0      0              *                LISTEN      13098/java

Use grep for filtering out the 8080 port.

You can use following command:
netstat -lpn | grep 8080

You’ll get output something like this

tcp        0      0  *               LISTEN      13098/java

Here my process id is 13098 and it is the process that is using port 8080

Kill the process using following command:
sudo kill 13098

Now port 8080 is free.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s