how to display the actual network traffic (wireless) in a terminal?
Additionally: Is it possible to add this info to the chart of top?
23 Answers
Here are some nice tools in the Ubuntu repositories for command line network traffic monitoring:
bmon - shows multiple interfaces at once
slurm - has nice colored graphs
tcptrack - A favorite. Tells how much bandwidth is being used and also what protocol (service/port) and destination the transmission is taking place to. Very helpful when you want to know exactly what is using up your bandwidth
It's quite easy! install "iftop" with:
sudo apt-get install iftopThen run
sudo iftopfrom any terminal!
Enjoy!
3Someone should also have mentioned nethogs.
sudo apt-get -y install nethogssudo nethogs
The thing that's different and maybe is cooler about this one is that it shows traffic per process, like the image shows
Take a look at the page
4There is a nice tool called speedometer that displays a graph in the terminal using Unicode block characters, colors, and even adds labels to each peak in the graph.
$ sudo apt-get install speedometer
$ speedometer -l -r wlan0 -t wlan0 -m $(( 1024 * 1024 * 3 / 2 ))It has several options, can monitor multiple interfaces, can show multiple graphs in several rows or columns, and can even monitor the download speed of a single file (by watching the file size on disk).
10iptraf
IPTraf is a console-based network statistics utility for Linux. It gathers a variety of figures such as TCP connection packet and byte counts, interface statistics and activity indicators, TCP/UDP traffic breakdowns, and LAN station packet and byte counts.
Features
An IP traffic monitor that shows information on the IP traffic passing over your network. Includes TCP flag information, packet and byte counts, ICMP details, OSPF packet types. General and detailed interface statistics showing IP, TCP, UDP, ICMP, non-IP and other IP packet counts, IP checksum errors, interface activity, packet size counts. A TCP and UDP service monitor showing counts of incoming and outgoing packets for common TCP and UDP application ports A LAN statistics module that discovers active hosts and shows statistics showing the data activity on them TCP, UDP, and other protocol display filters, allowing you to view only traffic you're interested in. Logging Supports Ethernet, FDDI, ISDN, SLIP, PPP, and loopback interface types. Utilizes the built-in raw socket interface of the Linux kernel, allowing it to be used over a wide range of supported network cards. Full-screen, menu-driven operation.
Protocols Recognized
IP TCP UDP ICMP IGMP IGP IGRP OSPF ARP RARP
Non-IP packets will simply be indicated as "Non-IP" and, on Ethernet LAN's, will be supplied with the appropriate Ethernet addresses.
Supported Interfaces
Local loopback All Linux-supported Ethernet interfaces All Linux-supported FDDI interfaces SLIP Asynchronous PPP Synchronous PPP over ISDN ISDN with Raw IP encapsulation ISDN with Cisco HDLC encapsulation Parallel Line IP
Source
Installation
With apt:
apt-get install iptrafOr download the source:
Screenshots
Current Connections:
Current Ports:
Summary of all Interfaces:
Detailed per Interface:
Source
2tcpdump -i eth0 That will give you a streaming information of all the data flowing from that interface (your ethernet card). Similar to wireshark.
Use ifconfig to see a list of your machines interfaces.
I think ifconfig [interface] will do that. Like:
gevorg@gevorg-TravelMate-3260:~$ ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr 00:18:de:89:52:71 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) gevorg@gevorg-TravelMate-3260:~$ ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:16:36:bf:92:e3 inet addr:192.168.10.100 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::216:36ff:febf:92e3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:342765 errors:0 dropped:0 overruns:0 frame:0 TX packets:306183 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:373934806 (373.9 MB) TX bytes:39111569 (39.1 MB) Interrupt:16
It shows RX bytes:73934806 (373.9 MB) and TX bytes:39111569 (39.1 MB).
2If you are looking for something extremely simple, but still useful, try ifstat
$ sudo apt-get install ifstat
$ ifstat eth0 wlan0 KB/s in KB/s out KB/s in KB/s out 0.00 0.00 0.96 4.79 0.00 0.00 0.04 0.14It monitors all interfaces at once, printing a new line every second. Useful to pipe into another script, or to leave running and observe the bandwidth usage over time. Not as pretty as other tools, but it gets the job done.
There are some useful options listed in the manpage:
-z Hides interface which counters are null, eg interfaces that are up but not used.
-n Turns off displaying the header periodically.
-t Adds a timestamp at the beginning of each line.
-T Reports total bandwith for all monitored interfaces.
-S Keep stats updated on the same line if possible (no scrolling nor wrapping).
-b Reports bandwith in kbits/sec instead of kbytes/sec. 1 This is not specific to networking, but Glances can display network traffic of different interfaces.
Install it with one of those commands :
sudo snap install glances
sudo apt install glances 1 Another useful tool is sar. Install it,
apt install sysstatHow to use it:
sar -n DEV 1And Brendan's amazing graph guide:
References
1Install ’vnstat’ it can show traffic for an interface. You can install some plotting packages to get some nice graphs.
1Also you could use iftop utility
Ifstat is good tool and it will give you all the interface network usage with respect to time.
sudo apt-get install ifstat According to ifconfig man:
This program is obsolete! For replacement check ip addr and ip link. For statistics use ip -s link.
So using ip command:
$ ip -s linkWe can get network stats:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 RX: bytes packets errors dropped overrun mcast 173654497900 26078946 0 0 0 0 TX: bytes packets errors dropped carrier collsns 173654497900 26078946 0 0 0 0
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 12:34:56:78:90:00 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 3650412438854 399476618 0 2551849 0 0 TX: bytes packets errors dropped carrier collsns 617437624480 321390259 0 0 0 0Or
$ ip -s -h link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 addrgenmode eui64 RX: bytes packets errors dropped overrun mcast 174G 26.1M 0 0 0 0 TX: bytes packets errors dropped carrier collsns 174G 26.1M 0 0 0 0 2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 12:34:56:78:90:00 brd ff:ff:ff:ff:ff:ff promiscuity 0 addrgenmode eui64 RX: bytes packets errors dropped overrun mcast 3.65T 399M 0 2.55M 0 0 TX: bytes packets errors dropped carrier collsns 617G 321M 0 0 0 0 Another possible tool is called nload.
Similar to slurm or bmon, but a little more simplistic.
I recently discovered wavemon which can easily be installed using apt-get install wavemon.
This tool provides information especially on the signal level of the wireless network.
And this is a blog showing a list of command to monitor bandwidth:
UPDATE:
I've been using NetHogs for about two months. It shows you total bandwidth usage. With the following setting you can additionally get bandwidth usage for each program
sudo nethogs -v 3
nettop is another option (not in the standard linux repos).
To build clone the repo:
git clone Install the dependencies:
sudo apt-get install libncurses5-dev libncursesw5-dev build-essential libpcap-devAnd build the binary:
makeRun with:
sudo ./nettopBtw, macos has a built-in utility called nettop which does the same thing but has more features.
This does the trick without needing to install anything special and without needing to be root either:
for i in {1..60};do echo `ifconfig eth0 | grep X.pa`;sleep 1;done replace eth0 with whatever interface you want to look at.
sample output:-
RX packets 7838573576 bytes 5261871317174 (4.7 TiB) TX packets 5420075700 bytes 2937680670358 (2.6 TiB)
RX packets 7838574080 bytes 5261871493163 (4.7 TiB) TX packets 5420076058 bytes 2937680745341 (2.6 TiB)
RX packets 7838574496 bytes 5261871573887 (4.7 TiB) TX packets 5420076379 bytes 2937680870613 (2.6 TiB) There is another tool called bandwhich
There's also conky.
You might have the package listed in your system's currently used repositories. Try running:
sudo apt-get install conky-allSome basic configuration info: Ubuntu Community Docs: Configuring Conky. CAUTION: The info on that site may be out of date, so please verify the steps listed there apply to your system.
Of course, a basic conky is very boring to look at, so here's a good conky theme to get you started:
Just follow the instructions on that page for setup; to install a particular theme, copy the .conkyrc file from the corresponding folder for the theme in the .harmattan-themes folder to your home directory.
Then, edit the file according to the instructions on the linked page.
TIP
Modify the file after copying it to your home folder, this way you get to keep the original un-altered files in case you need to re-copy the .conkyrc file for a theme.
For me, Slurm worked well:
Install:
sudo apt install slurmList interfaces
ifconfigMonitor interface (change eth0):
slurm -i eth0 1 VnStat is a fully-featured, command line-based program to monitor Linux network traffic and bandwidth utilization in real-time, on Linux and BSD systems.
Install:
sudo apt install sysstat 1