netstat - linux command
netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
Syntax
netstat [-a] [-n] [-v]
netstat [-g | -m | -p | -s | -f address_family ] [-n] [-P protocol]
netstat [ -i ] [ -I interface ] [ interval ]
netstat -r [-a] [-n] [-v ]
netstat -M [-n] [-s ]
netstat -D [ -I interface ]
-a
Show the state of all sockets and all routing table entries; normally, sockets used by server processes are not shown and only interface, host, network, and default routes are shown.
-n
Show network addresses as numbers. netstat normally displays addresses as symbols. This option may be used with any of the display formats.
-v
Verbose. Show additional information for the sockets and the routing table.
-g
Show the multicast group memberships for all interfaces.
-m
Show the STREAMS statistics.
-p
Show the address resolution (ARP) tables.
-s
Show per-protocol statistics. When used with the -M option, show multicast routing statistics instead.
-i
Show the state of the interfaces that are used for TCP/IP traffic.
-r
Show the routing tables.
-M
Show the multicast routing tables. When used with the -s option, show multicast routing statistics instead.
-d
Show the state of all interfaces that are under Dynamic Host Configuration Protocol (DHCP) control.
-D
Show the status of DHCP configured interfaces.
-f address_family
imit statistics or address control block reports to those of the specified address_family, which can be one of:
inet For the AF_INET address family
unix For the AF_Unix address family
-P protocol
Limit display of statistics or state of all sockets to those applicable to protocol.
- I interface
Show the state of a particular interface. interface can be any valid interface such as ie0 or le0.
Examples
netstat
Displays generic net statistics of the host you are currently connected to.
netstat -an
Shows all connections to the server including the source and destination ips and ports if you have proper permissions.
netstat -rn
Displays routing table for all ips bound to the server.
netstat -an |grep :80 |wc -l
Display the amount of active connections on port 80. Removing the pipe and wc command would display each connection.
netstat -natp
Display active Internet connections.