블로그

[리눅스] 네트웍 트래픽 확인 명령어들

리눅스 상에서 네트웍 트래픽을 확인할 수 있는 명령어들입니다.

텍스트 명령어들이라 정렬이 좀 깨지니 직접 실행해서 확인해 보는 것이 좋습니다.

/proc/net/dev 이용

# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  eth0: 9098017734 104667746    1 8618155    0     0          0         0 2421638354 9942192    0    0    0     0       0          0
    lo: 269553760 1993603    0    0    0     0          0         0 269553760 1993603    0    0    0     0       0          0

netstat 이용

# netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0  104670991      1 8618333 0       9942759      0      0      0 BMRU
lo        65536 0   1993744      0      0 0       1993744      0      0      0 LRU

프로그램에서 파싱해서 사용하기는 가장 깔끔한 듯 합니다.

# cat /sys/class/net/eth0/statistics/rx_bytes 
9098427059
# cat /sys/class/net/eth0/statistics/rx_packets 
104674127
# cat /sys/class/net/eth0/statistics/tx_bytes 
2421948275
# cat /sys/class/net/eth0/statistics/tx_packets 
9943572

ip 명령어 사용

# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast   
    269633296  1994075  0       0       0       0      
    TX: bytes  packets  errors  dropped carrier collsns 
    269633296  1994075  0       0       0       0      
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether d2:7e:f2:d1:57:eb brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast   
    9098556827 104676032 1       8618628 0       0      
    TX: bytes  packets  errors  dropped carrier collsns 
    2422036845 9943922  0       0       0       0 
2016-04-29 목록