LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2007, 11:16 AM   #1
ivanatora
Member
 
Registered: Sep 2003
Location: Bulgaria
Distribution: Ubuntu 9.10, FreeBSD 7.2
Posts: 459

Rep: Reputation: 32
Counting eth0/1 throughput, iptables?


Hello,
I have a linux gateway that serves 3-4 other PCs. I have one incoming line and I want to have graphical stats about total incoming speed.
MRTG is the tool, that is obvious. So I need to get somehow the current incomming bandwitdh at every moment.
First, I thought about SNMP, but I don't think I will need such a thing for so elementary purpose - only to measure one traffic load.
Second, more complex solution came into my mind - iptables. Marking all workstatins with:
iptables -A FORWARD -d 192.168.0.x -j ACCEPT
and after that counting bytes with:
iptables -L FORWARD -n -v -x
but that would require sum of all numbers, plus additional rule to check the traffic generated by the gateway itself... again seems to complicated. If you can help me think out a single iptables rule that can give me the number you would be great.

Third, I thought about ifconfig stats. There is something like:
RX bytes:3882164704 (3.6 GiB) TX bytes:3614255734 (3.3 GiB)
I can get these bytes and pass them to MRTG, but what will happen after restart when they became zeros?
 
Old 10-27-2007, 12:52 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by ivanatora View Post
I have a linux gateway that serves 3-4 other PCs. I have one incoming line and I want to have graphical stats about total incoming speed.
Quote:
If you can help me think out a single iptables rule that can give me the number you would be great.
An iptables rule does not require a targret; i.e. you don't need a -j option on it. W/o a target it will just sit there and collect statistics for you. So If I understand your request and setup correctly, probably a single rule at the beginning of the FORWARD chain something like

Code:
iptables -I FORWARD 1 -i <incoming interface> -d 192.168.0.0/24
would collect the statistics you want. I am assuming your incoming traffic is on a seperatate interface than your LAN. In addition or instead, you could match incoming with an address (such as ! 192.168.0.0/24, where the exclamation point means match anything else) or specifiy the output LAN interface with the -o option.
 
Old 10-28-2007, 09:34 AM   #3
ivanatora
Member
 
Registered: Sep 2003
Location: Bulgaria
Distribution: Ubuntu 9.10, FreeBSD 7.2
Posts: 459

Original Poster
Rep: Reputation: 32
Currently I use the following script:
Code:
ifconfig eth1|grep bytes|cut -d: -f2|cut -d" " -f1
ifconfig eth1|grep bytes|cut -d: -f3|cut -d" " -f1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ppp0 - eth0 without iptables not brctl? jago25_98 Linux - Networking 1 04-20-2010 04:25 AM
eth0 virtual interfaces & iptables Jukas Linux - Networking 2 07-27-2006 12:13 PM
Low eth0 throughput kel_en Debian 2 12-23-2005 07:18 AM
iptables with eth:0 and eth0:1 levand Linux - Security 11 12-09-2004 12:40 PM
iptables masq eth0,1,2,3 garvald Linux - Networking 0 08-06-2003 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration