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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@localhost:~# <strong>netstat -a</strong> | 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
1 2 3 4 5 6 7 |
root@localhost:~# <strong>netstat -at</strong> 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
1 2 3 4 5 |
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