Network Analysis: Netstat - S For Network Statistics
Network Analysis: Netstat - S For Network Statistics
Network Analysis
The problem with netstat is there is a staggering amount of information available. Try netstat -s for
network statistics.
#netstat -s
RAWIP
rawipInDatagrams = 0 rawipInErrors = 0
rawipInCksumErrs = 0 rawipOutDatagrams = 0
rawipOutErrors = 0
UDP
udpInDatagrams =17227479 udpInErrors = 0
udpOutDatagrams =17210476 udpOutErrors = 0
The statistics shown here are a small portion of first few screens of data! I am not an expert in all the
parameters, but a quick look at the error parameters such as tcpInErrs gives me an idea of the overall
health of the network.
You can also use netstat -a to examine for each port the number of bytes still waiting in the queue for
transmission and number of received bytes not copied to the application process by your server:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:netbios-ssn *:* LISTEN
tcp 0 0 *:webcache *:* LISTEN
tcp 0 0 *:x11 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 S34KLJ142:smtp *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 200.7.1.142:netbios-ssn 200.7.1.26:1352 ESTABLISHED
tcp 0 0 200.7.1.142:33568 200.1.34.117:1521
tcp 0 180 200.7.1.142:ssh 200.7.1.25:1404 ESTABLISHED
Note that ssh still has 180 bytes of data to transmit in its queue. Not a problem, but this could be a
problem if the value is very large (meaning that the ssh data cannot be transmited fast enough, so it has
to be queued).
I also find it quite useful to use simple real-world benchmarks to analyze network performance, such as
the time required to transfer a 10 megabyte file (should be 10-15 seconds on a 10 Mbit network), or
using the apachebench ab -c1000 -n10 [url] command to simulate 10 clients sending a total of 1000
http requests to a server.
Network Response
$ netstat -i
Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue lo0 8232 loopback localhost 77814
0 77814 0 0 0 hme0 1500 server1 server1 10658566 3 4832511 0 279257 0 This option is used to
diagnose the network problems when the connectivity is there but it is slow in response .
Netstat gives important information about network socket and tcp state . This is very useful in
finding out the open , closed and waiting network tcp connection .
CLOSED ---- Closed. The socket is not being used.
LISTEN ---- Listening for incoming connections.
SYN_SENT ---- Actively trying to establish connection.
SYN_RECEIVED ---- Initial synchronization of the connection under way.
ESTABLISHED ---- Connection has been established.
CLOSE_WAIT ---- Remote shut down; waiting for the socket to close.
FIN_WAIT_1 ---- Socket closed; shutting down connection.
CLOSING ---- Closed, then remote shutdown; awaiting acknowledgement.
LAST_ACK ---- Remote shut down, then closed ;awaiting acknowledgement.
FIN_WAIT_2 ---- Socket closed; waiting for shutdown from remote.
TIME_WAIT ---- Wait after close for remote shutdown retransmission.
Example:
#netstat -a
192.168.1.184.22192.168.1.183.58672180480246160ESTABLISHED
if you see
192.168.1.184.22192.168.1.186.56806389120246160ESTABLISHED
a lots of
192.168.1.184.22192.168.1.186.50457419920246160ESTABLISHED
*.**.*00245760IDLE
*.32776*.*00245760LISTEN
*.32775*.*00245760LISTEN
*.32772*.*00245760LISTEN
*.898*.*00245760LISTEN
*.5987*.*00245760LISTEN
*.25*.*00245760LISTEN
*.4045*.*00245760LISTEN
*.32771*.*00245760LISTEN
*.**.*00245760IDLE
*.22*.*00245760LISTEN
*.22*.*00245760LISTEN
*.**.*00245760IDLE
connections in FIN_WAIT state tcp/ip parameters have to be tuned because the
connections are not being closed and they gets accumulating . After some time system may run out of
resource . TCP parameter can be tuned to define a time out so that connections can be released and
used by new connection.