Wednesday, 9 February 2011

What Linux process is listening?

One of the fastest ways to find out which port/IP your process is listening on is to use netstat. A command line tool that displays network connections and interface stats as well as routing tables.

Example netstat command:
netstat -tulpn


Example netstat output:


[email protected]:/# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      760/memcached
tcp        0      0 10.112.234.39:80        0.0.0.0:*               LISTEN      1468/haproxy
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      730/perl
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      300/sshd
tcp        0      0 10.112.234.39:443       0.0.0.0:*               LISTEN      1468/haproxy
tcp        0      0 0.0.0.0:5666            0.0.0.0:*               LISTEN      579/nrpe
tcp6       0      0 :::11211                :::*                    LISTEN      760/memcached
tcp6       0      0 :::22                   :::*                    LISTEN      300/sshd
udp        0      0 0.0.0.0:41668           0.0.0.0:*                           620/snmpd
udp        0      0 0.0.0.0:68              0.0.0.0:*                           307/dhclient3
udp        0      0 0.0.0.0:11211           0.0.0.0:*                           760/memcached
udp        0      0 0.0.0.0:50527           0.0.0.0:*                           1468/haproxy
udp        0      0 0.0.0.0:10000           0.0.0.0:*                           730/perl
udp        0      0 127.0.0.1:161           0.0.0.0:*                           620/snmpd
udp6       0      0 :::11211                :::*                                760/memcached

Further, if you want to drill into only HTTP, for example:
netstat -tulpn | grep :80



And we can see HAProxy listening for HTTP traffic on TCP:80:
tcp        0      0 10.112.234.39:80        0.0.0.0:*               LISTEN      1468/haproxy

No comments:

Post a Comment