21

Is there a way to monitor the traffic (e.g., get a live view of the utilization) over a particular network interface, say eth0?

The catch here is that the set of tools on the box is fixed, and is pretty much a stock RHEL deployment, so add-on tools can't be used.

Looking for something basic and usually present like iostat here.

BeeOnRope
  • 573
  • 3
  • 6
  • 12
  • 1
    Have a look at http://stackoverflow.com/questions/596590/how-can-i-get-the-current-network-interface-throughput-statistics-on-linux-unix. Some of the suggestions on there should be useful. – Andy Smith Dec 02 '11 at 01:15
  • D'oh, search fail (and I tried). To be fair, I think it's a serverfault question, not a SO one :) – BeeOnRope Dec 02 '11 at 22:41

9 Answers9

23

The data you want to see shows up in good old ifconfig.

watch ifconfig eth0

or to make things stand out better:

watch -n 1 -d ifconfig eth0
thinice
  • 4,716
  • 21
  • 38
Joel K
  • 5,853
  • 2
  • 30
  • 34
  • Thanks - this in addition to the comment by @user239558 was just right. I'm accepting your answer since you were the first to mention `ifconfig`. – BeeOnRope Jan 22 '16 at 00:28
  • Spot on. This is something I've been looking for and although there are many similar questions to this on different forums, this is the first answer I found that nails it. – Hazok Jun 09 '16 at 18:34
  • ifconfig is not in the default path. /sbin/ifconfig may be required. – Kevin Apr 06 '18 at 21:22
19

I use iftop command. It shows statistics in realtime.

iftop -i eth0

Checkout some sceenshots here:

http://www.thegeekstuff.com/2008/12/iftop-guide-display-network-interface-bandwidth-usage-on-linux/

Awi
  • 291
  • 1
  • 3
7

on post-2015 or so linux this might be better watch -n1 -d ip -s link show [interface]

massemanet
  • 69
  • 1
  • 2
4

Without installing new tools:

while ifconfig eth0 | grep 'RX bytes'; do sleep 10; done

user239558
  • 141
  • 6
4
function humanValue()
{
    h=( '' K M G T P )
    i=1; v=$(( $1 * 8 ))
    while [ $v -gt $(( 1 << 10 * i )) ]; do let i++; done;
    echo -n "$(( $v >> 10 * --i )) ${h[i]}b/s";
}
ifaces=$(ip addr | grep -E "^[0-9]:" | cut -d" " -f2 | tr -d \:)
declare -A RX2 TX2;
while sleep 1; 
do
    date 
    for INTERFACE in $ifaces;
    do
        RX1=$(cat /sys/class/net/${INTERFACE}/statistics/rx_bytes)
        TX1=$(cat /sys/class/net/${INTERFACE}/statistics/tx_bytes)
        DOWN=$(( RX1 - RX2[$INTERFACE] ))
        UP=$(( TX1 - TX2[$INTERFACE] ))
        RX2[$INTERFACE]=$RX1; TX2[$INTERFACE]=$TX1
        echo -e "[ $INTERFACE:\tRX: $(humanValue $DOWN)\t|\tTX: $(humanValue $UP) ]"
    done;
done;
ton
  • 180
  • 4
2

There are a lot of utilities:

  1. Nethogs
  2. iptraf
  3. Iptables can be a good solution to but if you are using a firewall set up will be a bit hard to relocate correctly the rules
quanta
  • 51,413
  • 19
  • 159
  • 217
dSoultanis
  • 336
  • 1
  • 4
  • iptraf is exactly what i was looking for. But its last release seems be in IPTraf 3.0.0 - September 19, 2005. can this be a problem? – Al-Alamin Apr 25 '18 at 09:42
2

You can also use iptables to do such think:

iptables -A INPUT -p tcp --dport $port -i eth0

and

iptables -A OUTPUT -p tcp --sport $port -i eth0

Then iptables -L -n -v will print you how many packets have been going through the interface, iptables -Z to zero this count

philippe
  • 2,303
  • 4
  • 32
  • 53
1

Take a look at ntop. It provides a lot of detailed data.

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
Nicholas
  • 207
  • 1
  • 7
0

You can use

netstat -w8 -h -i eth0

Which will display bits/sand in/out. -w8 Waits 8 seconds, -h converts output to humand readable numbers. Works in Linux/FreeBSD.

bjoster
  • 4,805
  • 5
  • 25
  • 33