Netstat – Network Statistics
Netstat monitors both incoming and outgoing network connections, displays the routing table, interface statistics, multicast memberships, lists open ports, lists programs listening on any ports and masquerade connections. Applied in troubleshooting network issues and monitoring network performance.
Display all listening sockets using tcp while showing only numerical addresses. This is applied when you are running a program which is using specific socket(s) on tcp protocol and you want to check if the socket(s) is/are opened.
$ netstat -aln --tcp
Display all listening sockets using tcp while showing only resolved names
$ netstat -al --tcp
Other options of netstat
Display network interface statistics and specifically ip connections. Gives similar output to “ifconfig”
$ netstat -inet
Display statistics for only tcp protocol
$ netstat -st | less
List all the programs holding socket and their respective PID number
$ netstat -p | less
Display the routing table (Similar to “route -e” command)
$ netstat -r
Nethogs - Monitor Per Process Network Bandwidth
NetHogs monitors network activity of each process, displaying bandwidth of each process while sorting from the most intensive process to the least intensive. This is applied to view the processes utilizing the most network bandwidth in REAL TIME. The details of the process shown are PID, process name/path and user running the process.
$ sudo nethogs
Special Note: Incase nethogs is not installed, you can install as follows depending on your linux flavor.
For Centos
$ sudo yum install epel-release $ sudo yum install -y nethogs
For Ubuntu
$ sudo apt-get install nethogs
Other options of nethogs
Display nethogs output with a refresh rate of 3 seconds
$ sudo nethogs -d 3
Display nethogs output for specific network interface
$ sudo nethogs eth0
Iftop – Monitor Network Bandwidth Utilization
iftop acts similarly to “top” (CPU usage) command but now for network usage. It shows the network bandwidth i.e. transmitted and received packets per network interface in REAL TIME. It also shows the source and destination hosts sending and receiving the packets. It’s applied when system admin needs to know why specific network link is slow.
$ sudo iftop
Special Note: Incase iftop is not installed, you can install as follows depending on your linux flavor.
For Centos
$ sudo yum install epel-release $ sudo yum install -y iftop
For Ubuntu
$ sudo apt-get install iftop
To show only numerical addresses
$ sudo iftop -n
Other options of iftop
Monitor network bandwidth on specific network interface with resolved names
$ sudo iftop -i eth0
Monitor network bandwidth on specific network interface with numerical addresses
$ sudo iftop -n eth0
Display ports
$ sudo iftop -P
ss - Socket Statistics
ss displays socket statistics similarly to netstat. It displays more TCP and state information than other tools. By-default it shows all open non-listening sockets on TCP/UNIX/UDP that have established connection.
$ ss | less
List all the currently opened network ports
$ ss -l | less
Check out the top 3 Linux hosting services