Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Since ifconfig is apparently being deprecated in major Linux distributions, I thought I'd learn something about the ip tool that's supposed to be used instead of ifconfig.

And here I ran into a problem: when run on its own, ifconfig shows the number of bytes received/transmitted on each interface besides other info. I couldn't find a way to get this from ip. Is there no such function in this tool? What other built-in tools could I use for getting those stats?

share|improve this question
    
You can also check out netstat. linux.die.net/man/8/netstat –  SunSparc Aug 24 '13 at 20:20

3 Answers 3

up vote 12 down vote accepted

Another option is to use the /proc filesystem. The /proc/net/dev file contains statistics about the configured network interfaces. Each line is dedicated to one network interface and it contains statistics for receive and transmit. The statistics include metrics such total number of received/transmittted bytes, packets, drops, errors and so on.

cat /proc/net/dev

    Inter-|   Receive                                                |  Transmit
     face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed

    lo:    29846937   129576     0    0    0     0          0       0 29846937   129576     0    0    0     0       0          0
 wlan0:    9467393340 8027251    0    0    0     0          0       0 2559312961 5896509    0    0    0     0       0          0

Or you can try the netstat command which can display all network interfaces and related statistics:

netstat -i

Iface   MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
lo         65536   0   130435      0      0      0   130435      0      0      0 LRU
wlan0       1492   0  8028018      0      0      0  5897361      0      0      0 BMRU
share|improve this answer
    
/proc/net/dev has the cleanest format of all of the solutions IMO, accepting. –  justinas Aug 25 '13 at 15:23
    
Stats showed by cat /proc/net/dev are for how long time ? –  lalebarde Jul 18 at 10:35

You can get all necessary info via proc

# cat /sys/class/net/eth0/statistics/rx_bytes
# cat /sys/class/net/eth0/statistics/rx_packets

# cat /sys/class/net/eth0/statistics/tx_packets
# cat /sys/class/net/eth0/statistics/tx_bytes

Also you can use iptables and parse output.

For received packets

# iptables -L INPUT -n -v

for transmitted packets

# iptables -L OUTPUT -n -v 

If server is a gateway, then you should also parse FORWARD chain

share|improve this answer

The ip command which is part of the the iproute2 package is the new tool. The link subcommand is for managing the devices/interfaces.

If you can get the stats of an interface using ip -s link

root:~# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast
    50679705   529967   0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    50679705   529967   0       0       0       0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:1d:7d:aa:e3:4e brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    187663757  308710386 0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    4051284587 532435117 0       0       0       0
share|improve this answer
    
While the proc answer is clean and lightweight, this answer is probably the closest to a "replacement" for the ifconfig tool because it was explicitly designed with replacement of ifconfig in mind. –  Moshe Katz Aug 29 '13 at 20:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.