netstat command (Network Statistics)
netstat displays the contents of various network-related data structures in depending on the options selected.
Syntax:
netstat < option/s >
multiple options can be given at one time.
-a : displays the state of all sockets.
netstat displays the contents of various network-related data structures in depending on the options selected.
Syntax:
netstat < option/s >
multiple options can be given at one time.
-a : displays the state of all sockets.
-r : shows the system routing tables
-i : gives statistics on a per-interface basis.
-m : displays information from the network memory buffers. On Solaris, this shows statistics for STREAMS
-p [proto] : retrieves statistics for the specified protocol
-s : shows per-protocol statistics.
-i : gives statistics on a per-interface basis.
-m : displays information from the network memory buffers. On Solaris, this shows statistics for STREAMS
-p [proto] : retrieves statistics for the specified protocol
-s : shows per-protocol statistics.
(some implementations allow -ss to remove fileds with a value of 0 (zero) from the display.)
-D : display the status of DHCP configured interfaces.
-D : display the status of DHCP configured interfaces.
-n : do not lookup hostnames, display only IP addresses.
-d (with -i) : displays dropped packets per interface.
-I [interface] retrieve information about only the specified interface.
-d (with -i) : displays dropped packets per interface.
-I [interface] retrieve information about only the specified interface.
-v : be verbose
interval : number for continuous display of statictics.
interval : number for continuous display of statictics.
$netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
192.168.1.0 192.168.1.11 U 1 1444 le0
224.0.0.0 192.168.1.11 U 1 0 le0
default 192.168.1.1 UG 1 68276
127.0.0.1 127.0.0.1 UH 1 10497 lo0
This shows the output on a Solaris machine who's IP address is 192.168.1.11 with a default router at 192.168.1.1
Other important options with netstat:
netstat -an | grep LISTEN | grep xxxx to grep for the port number
If you want to see what ports processes are listening on at a given moment and get a sorted list so you can see where there might be an available port,
If you want to see what ports processes are listening on at a given moment and get a sorted list so you can see where there might be an available port,
you can use the command below:
netstat -an | grep LISTEN | awk '{print substr($1,3)}' | sort –n
netstat -an | grep LISTEN | awk '{print substr($1,3)}' | sort –n
Netstat –anP tcp | grep ipaddress | wc –l to grep the number of connections to the web server.