Linux netstat Command: Network Connections, Routes and Statistics
The netstat command in Linux is part of the old legacy Net-Tools package and displays network connections, routing tables, interface statistics, etc. It was elegantly replaced by the "ss" command.
Examples:
# netstat -anpActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 981/mysqldtcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 24929/mini-apache:tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 2160/httpdtcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN 1994/(squid)tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 935/named
In this example the netstat command lists all open connections and processes that are listening for connections and to which process they belong. The "-p" option only shows the programs "owning" the connections to root.
The -i option provides a volume statistic of data traffic on each interface:
$ netstat -i
Tabela de Interfaces do Kernel
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 9001 34849988 0 0 0 30552900 0 0 0 BMRU
lo 65536 4407543 0 0 0 4407543 0 0 0 LRU
The "-r" option shows the routing table, much like the route command:
$ netstat -rnTabela de Roteamento IP do KernelDestino Roteador MáscaraGen. Opções MSS Janela irtt Iface0.0.0.0 172.30.0.1 0.0.0.0 UG 0 0 0 eth010.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun010.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0169.254.169.254 0.0.0.0 255.255.255.255 UH 0 0 0 eth0172.30.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
netstat also provides network interface statistics with the "-s" option:
$ netstat -sIp: 8871 total packets received 0 forwarded 0 incoming packets discarded 7997 incoming packets delivered 5023 requests sent out( ... )
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Liked it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.