netstat

From Initq
Jump to: navigation, search

Print network connections, routing tables, interface statistics, masquerade con‐nections, and multicast memberships.

Contents

Flags

-c continous
-n numeric
-t tcp
-u udp
-l listening
-a all
-p programs
-o timer
-s statistics
-r routing
-C cache

Stats -sap

Print Stats, excellent for checking for dropped packets.

root@initq:~# netstat -sap
Ip:
    135072930 total packets received
    0 forwarded
    0 incoming packets discarded
    134730796 incoming packets delivered
    162626118 requests sent out
 
root@initq:~# netstat -sap | grep -i drop
    4 ICMP packets dropped because they were out-of-window
    TCPDeferAcceptDrop: 34838

All tcp programs -tap

This flag shows us all tcp programs.

root@initq:~# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:www                   *:*                     LISTEN      6150/apache2    
tcp        0      0 *:6544                  *:*                     LISTEN      2007/mythbackend
tcp        0      0 *:ssh                   *:*                     LISTEN      1125/sshd       
tcp        0      0 localhost.localdoma:ipp *:*                     LISTEN      31426/cupsd

All tcp programs numeric -nap

root@initq:~# netstat -nap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6150/apache2    
tcp        0      0 0.0.0.0:6544            0.0.0.0:*               LISTEN      2007/mythbackend
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1125/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      31426/cupsd     
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1832/master     
tcp        0      0 0.0.0.0:47304           0.0.0.0:*               LISTEN      899/rpc.statd   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1753/mysqld

All tcp and udp

root@initq:~# netstat -tuap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:www                   *:*                     LISTEN      6150/apache2    
tcp        0      0 *:6544                  *:*                     LISTEN      2007/mythbackend
tcp        0      0 *:ssh                   *:*                     LISTEN      1125/sshd       
tcp        0      0 localhost.localdoma:ipp *:*                     LISTEN      31426/cupsd     
tcp        0      0 *:smtp                  *:*                     LISTEN      1832/master     
tcp        0      0 *:47304                 *:*                     LISTEN      899/rpc.statd

All listening ports -tulp

root@initq:~# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:www                   *:*                     LISTEN      6150/apache2    
tcp        0      0 *:6544                  *:*                     LISTEN      2007/mythbackend
tcp        0      0 *:ssh                   *:*                     LISTEN      1125/sshd       
tcp        0      0 localhost.localdoma:ipp *:*                     LISTEN      31426/cupsd     
tcp        0      0 *:smtp                  *:*                     LISTEN      1832/master     
tcp        0      0 *:47304                 *:*                     LISTEN      899/rpc.statd   
tcp        0      0 localhost.localdo:mysql *:*                     LISTEN      1753/mysqld

Live watch -tuc

root@initq:~# netstat -tuc -o 3
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       Timer
tcp        0      0 initq.local:36475       ohnonono.l:microsoft-ds ESTABLISHED off (0.00/0/0)
tcp        0      0 adsl-99-54-115-12:46611 baymsg1030113.gate:msnp ESTABLISHED off (0.00/0/0)
tcp        0      0 adsl-99-54-115-12:42442 yi-in-f125.:xmpp-client ESTABLISHED off (0.00/0/0)

Live watch with timer

[root@localhost ~]# netstat -tuc -o 3
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       Timer
tcp        0     48 10.0.2.15:ssh               192.168.1.20:59872          ESTABLISHED on (0.22/0/0)

Routing Cache -rnC

root@initq:~# netstat -rnC
Kernel IP routing cache
Source          Destination     Gateway         Flags   MSS Window  irtt Iface
119.63.196.97   99.54.115.124   99.54.115.124   l     16436 0          0 lo
99.54.115.124   72.21.91.19     99.54.115.126          1500 0          0 eth0
74.125.227.33   99.54.115.124   99.54.115.124   l     16436 0          0 lo
192.168.1.20    192.168.1.2     192.168.1.2            1500 0          0 eth1
99.54.115.124   74.125.227.39   99.54.115.126          1500 0          0 eth0
192.168.1.10    224.0.0.251     224.0.0.251     ml    16436 0          0 lo
99.54.115.124   216.137.43.11   99.54.115.126          1500 0          0 eth0

Routing table -rn

root@initq:~# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
99.54.115.120   0.0.0.0         255.255.255.248 U         0 0          0 eth0
Personal tools