Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.

List All Ports (both listening and non listening ports)
#netstat -a

root@localhost:~# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
udp 0 0 *:openvpn *:*

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 8963 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 9988 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 10048 private/proxymap

List all tcp ports
#netstat -at

root@localhost:~# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN

Find out on which port a program is running
#netstat -ap

root@localhost:~# netstat -ap | grep http
tcp 0 0 *:http *:* LISTEN 1050/apache2
tcp 0 0 192.168.50.11:http 192.168.18.1:51615 TIME_WAIT -
tcp 0 0 192.168.50.11:http 192.168.18.1:51620 TIME_WAIT -
tcp 0 0 192.168.50.11:http 192.168.18.1:51614 TIME_WAIT -

Find more on netstat manual.

 

 

 

 

 

Linux: Netstat Command Examples
Tagged on:                 

Leave a Reply

Your email address will not be published. Required fields are marked *