cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

os:linux:command:netstat.html



Linux Commands#performance

How to use netstat command on Linux



Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

netstat -h

# netstat -h

        -r, --route              display routing table
        -i, --interfaces         display interface table
        -s, --statistics         display networking statistics (like SNMP)

        -p, --programs           display PID/Program name for sockets
        -n, --numeric            don't resolve names
        -a, --all                display all sockets (default: connected)


man netstat

#man netstat

       netstat {--help|-h}

OPTIONS
   --route , -r
       Display the kernel routing tables. See the description in route(8) for details.
       netstat -r and route -e produce the same output.

   --interfaces=iface , -I=iface , -i
       Display a table of all network interfaces, or the specified iface.

   --statistics , -s
       Display summary statistics for each protocol.

OPTIONS
   --numeric , -n
       Show numerical addresses instead of trying to determine symbolic host, port or user names.

   -p, --program
       Show the PID and name of the program to which each socket belongs.

   -a, --all
       Show both listening and non-listening (for TCP this means established connections) sockets.
       With the --interfaces option, show inter‐faces that are not up


Example

netstat -rn

# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 enp0s3
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
192.168.10.0    0.0.0.0         255.255.255.0   U         0 0          0 br-295e2a4e2c26

netstat -anp

# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:199           0.0.0.0:*               LISTEN      949/snmpd
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      942/php-fpm: master
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1328/mysqld
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      970/nginx: master p
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      970/nginx: master p
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      945/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1425/master
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      966/zabbix_agentd
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      1008/zabbix_server
tcp        0     96 192.168.0.22:22         192.168.0.9:62742       ESTABLISHED 1594/sshd: root@pts
tcp6       0      0 :::22                   :::*                    LISTEN      945/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1425/master
tcp6       0      0 :::10050                :::*                    LISTEN      966/zabbix_agentd
tcp6       0      0 :::10051                :::*                    LISTEN      1008/zabbix_server
udp        0      0 0.0.0.0:11728           0.0.0.0:*                           744/dhclient
udp        0      0 0.0.0.0:68              0.0.0.0:*                           744/dhclient
udp        0      0 0.0.0.0:161             0.0.0.0:*                           949/snmpd
udp        0      0 192.168.0.22:59110      13.230.38.136:123       ESTABLISHED 672/chronyd
udp        0      0 127.0.0.1:323           0.0.0.0:*                           672/chronyd
udp6       0      0 :::4433                 :::*                                744/dhclient
udp6       0      0 ::1:323                 :::*                                672/chronyd
raw6       0      0 :::58                   :::*                    7           675/NetworkManager

netstat -i

# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
br-295e2  1500     1273      0      0 0           703      0      0      0 BMU
docker0   1500        0      0      0 0             0      0      0      0 BMU
enp0s3    1500     1273      0      0 0           703      0      0      0 BMRU
lo       65536     3202      0      0 0          3202      0      0      0 LRU

netstat -s

# netstat -s
Ip:
    4461 total packets received
    0 forwarded
    0 incoming packets discarded
    4456 incoming packets delivered
    3893 requests sent out
    4 dropped because of missing route
Icmp:
    0 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
    4 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 4
IcmpMsg:
        OutType3: 4
Tcp:
    322 active connections openings
    324 passive connection openings
    1 failed connection attempts
    0 connection resets received
    1 connections established
    4410 segments received
    3872 segments send out
    0 segments retransmited
    0 bad segments received.
    9 resets sent
(abbr)







Linux Commands#performance




os/linux/command/netstat.html.txt · Last modified: 2019/03/19 by admin

Page Tools