Friday, June 11, 2010

Identify the ports in linux

For socket programming, you need to use the port. If you want to identify the ports which are active, you can use the following commands. Generally in linux, the ports from 0 to 1023 are reserved and can be accessed only as a root user.

For checking the information about the port, you can use netstat

If you want to know more about this command, you can check its man page
$ man netstat

But for quick reference, you can use any of these for the appropriate purpose.

For finding the open ports:
$ netstat --listen

For finding the open ports and established TCP connections:
$ netstat -vatn

For checking information about a port,
$ netstat -anp | grep <port>

For identifying the ports already in use:
$ netstat -atnp | grep LISTEN

No comments: