Как я могу отслеживать загрузку / скачивание через Интернет на Linux, игнорируя при этом локальный трафик?

253
rexxster

У меня есть две коробки Linux, подключенные к маршрутизатору, и маршрутизатор подключен к модему. Компьютеры Linux совместно используют файловые системы через NFS. Я хочу отслеживать загрузку и загрузку в Интернете, игнорируя локальный (nfs / ssh) трафик. Я бы предпочел вытащить эти значения из /proc. Ищете минимальное решение для обработки мощности. Какие-либо предложения?

0

2 ответа на вопрос

0
Julian Knight

If you want to track internet traffic as a whole, the only way is from the router not the individual machines.

Check if your router supports SNMP. If it does you can get an snmp client for Linux on one of the PCs to monitor the network usage of the WAN interface on the router (that's the external interface) which will show you the total traffic in/out of the Internet.

Anything else will be complex since you would need to filter out any local traffic from the machines & the router.

Я забочусь только о трафике в / из интернета из одной коробки. rexxster 8 лет назад 0
Но этот блок подключен к локальной сети, а не напрямую к Интернету, поэтому другой трафик присутствует. Чтобы сделать больше, требуется более сложный сетевой монитор, который может отфильтровывать все, кроме интересующего вас трафика. Julian Knight 8 лет назад 0
0
davychiu

You can add two rules to iptables to segment out the packets going to and from the internet. Note you will have to adapt them to your system and network settings. I'm assuming network interface name eth1 and 192.168.0.0/24.

iptables -I INPUT 1 -i eth0 ! -s 192.168.0.0/24 iptables -I OUTPUT 1 -o eth0 ! -d 192.168.0.0/24 

Then you can see the bandwidth usage like this:

# iptables -nvx -L INPUT Chain INPUT (policy ACCEPT 542 packets, 63745 bytes) pkts bytes target prot opt in out source destination 35 4533 all -- eth0 * ! 192.169.0.0/24 0.0.0.0/0 # iptables -nvx -L OUTPUT Chain OUTPUT (policy ACCEPT 247 packets, 27847 bytes) pkts bytes target prot opt in out source destination 48 4724 all -- * eth0 0.0.0.0/0 ! 192.168.0.0/24 

Похожие вопросы