Skip to contentSkip to conversation

track bandwith used

DISCUSSION Peter Marshall 3 participants 9 messages Jun 30, 2004 – Jul 1, 2004

lore
Share & tools
lore
#0 lore raw

Hi again,

I was also wondering if anyone knows a way to track bandwith being used through the firewall .......
I use squid as a proxy behind the firewall if that helps at all ...

Thank you again,
Peter

#1 lore raw
Quoted 4 lines · Peter Marshall

Hi again,

I was also wondering if anyone knows a way to track bandwith being used through the firewall .......

Well, there are plenty of network monitoring tools which will give you this sort of information as an aggregate figure for an interface, or broken down by source/destination address, port number etc - iptraf is not a bad start to see what can be done.

Other than that you can use netfilter rules to count the packets & bytes, and then use a cron job to record the counts at whatever intervals you want (every minute, every hour, every day...), and then process them yourself.

Things I would mention if you're going to try the latter option:

1. Most packets do not match against rules in the nat table, so don't try counting those - the only packets which match these are the first of each connection - all the rest are processed invisibly by netfilter in the background, and your rules don't see them (this is also the reason why you should never set a default DROP policy on a nat table!)

2. If you are using a standard -m state --state ESTABLISHED,RELATED rule in your FORWARD chain, remember that nearly all packets will match that, no matter which direction they're going through the machine, and which port/s
they're going to or from. Again, most of the rules in your FORWARD chain
will only match the first packet of a given connection, so you won't see much traffic on these rules either (although they can give you a useful indication of the number of connections of that type which get created).

3. The FORWARD mangle table can be a good place to put rules which will see all traffic going through the system.

4. For accounting purposes, you can quite readily use rules with no target (eg: iptables -A FORWARD -p tcp --dport 25); these will make no difference to whether the packets are ACCEPTed, DROPped, LOGged, REJECTed, or whatever (obviously you need separate rules to do that somewhere else), but the packet & byte counters from iptables -L -nvx will show you how many of that type of
packet were seen. You can make the rules as specific as you like if you
want to count certain connections in minute detail (eg: iptables -A FORWARD -p tcp --dport 25 -s my.mail.ser.ver -d ISP.mail.ser.ver)

5. Don't overlook the raw packet & byte counts available from ifconfig if all you want to do is monitor traffic in & out of an interface.

Hope this give you some ideas.

Regards,

Antony.

Signature · 6 lines
"The future is already here.   It's just not evenly distributed yet."

 - William Gibson

                                                     Please reply to the list;
                                                           please don't CC me.
#2 lore raw

ya, that was great. I guess there was one thing that you said that worried me ... you said almost all packets will match the ESTABLISHED,RELATED check on the forwared chain ... would that not be a bad thing ... is it dangerous to have RELATED as an option on the FORWAED CHAIN.

???

Thankls

----- Original Message -----
From: "Antony Stone" <[email protected]>
To: "netfilter" <[email protected]>
Sent: Wednesday, June 30, 2004 10:41 AM
Subject: Re: track bandwith used

Quoted 4 lines · Peter Marshall

Hi again,

I was also wondering if anyone knows a way to track bandwith being used through the firewall .......

Well, there are plenty of network monitoring tools which will give you this sort of information as an aggregate figure for an interface, or broken down by source/destination address, port number etc - iptraf is not a bad start to
see what can be done.

Other than that you can use netfilter rules to count the packets & bytes, and
then use a cron job to record the counts at whatever intervals you want (every minute, every hour, every day...), and then process them yourself.

Things I would mention if you're going to try the latter option:

1. Most packets do not match against rules in the nat table, so don't try counting those - the only packets which match these are the first of each connection - all the rest are processed invisibly by netfilter in the background, and your rules don't see them (this is also the reason why you should never set a default DROP policy on a nat table!)

2. If you are using a standard -m state --state ESTABLISHED,RELATED rule in your FORWARD chain, remember that nearly all packets will match that, no matter which direction they're going through the machine, and which port/s
they're going to or from. Again, most of the rules in your FORWARD chain
will only match the first packet of a given connection, so you won't see much
traffic on these rules either (although they can give you a useful indication
of the number of connections of that type which get created).

3. The FORWARD mangle table can be a good place to put rules which will see all traffic going through the system.

4. For accounting purposes, you can quite readily use rules with no target (eg: iptables -A FORWARD -p tcp --dport 25); these will make no difference to
whether the packets are ACCEPTed, DROPped, LOGged, REJECTed, or whatever (obviously you need separate rules to do that somewhere else), but the packet
& byte counters from iptables -L -nvx will show you how many of that type of
packet were seen. You can make the rules as specific as you like if you
want to count certain connections in minute detail (eg: iptables -A FORWARD -p tcp --dport 25 -s my.mail.ser.ver -d ISP.mail.ser.ver)

5. Don't overlook the raw packet & byte counts available from ifconfig if all
you want to do is monitor traffic in & out of an interface.

Hope this give you some ideas.

Regards,

Antony.

Signature · 8 lines
"The future is already here.   It's just not evenly distributed yet."

 - William Gibson

                                                     Please reply to the
list;
                                                           please don't CC
me.
#3 lore raw
Quoted 4 lines · Peter Marshall

ya, that was great. I guess there was one thing that you said that worried me ... you said almost all packets will match the ESTABLISHED,RELATED check on the forwared chain ... would that not be a bad thing ... is it dangerous to have RELATED as an option on the FORWARD CHAIN. ???

No, in fact it is essential for many purposes.

1. The FTP data channel will be matched as RELATED to the initial control channel, so RELATED in FORWARD is needed if you are going to allow FTP.

2. ICMP error responses (usually seen in reply to UDP packets which fail for some reason) match as RELATED, and (as is already being discussed on another thread on this list), it is not a good idea to stop all ICMP packets from getting through your firewall.

There are other examples of why RELATED packets are necessary, but these are the most common and obvious ones.

You will generally find that all tutorials and netfilter examples match ESTABLISHED and RELATED in the FORWARD chain.

What makes you think that RELATED is dangerous?

Regards,

Antony.

Signature · 6 lines
The words "e pluribus unum" on the Great Seal of the United States are from a 
poem by Virgil entitled "Moretum", which is about cheese and garlic salad 
dressing.

                                                     Please reply to the list;
                                                           please don't CC me.
#4 lore raw

You could make a connection out to a remote server. That remote server might try to make a connection back to us that has nothing to do with the reason we connectd to them. But the server may see it as related and allow it.

----- Original Message -----
From: "Antony Stone" <[email protected]>
To: "netfilter" <[email protected]>
Sent: Wednesday, June 30, 2004 1:17 PM
Subject: Re: track bandwith used

Quoted 1 line · Peter Marshall

ya, that was great. I guess there was one thing that you said that

worried

Quoted 1 line

me ... you said almost all packets will match the ESTABLISHED,RELATED

check

Quoted 1 line

on the forwared chain ... would that not be a bad thing ... is it

dangerous

Quoted 1 line

to have RELATED as an option on the FORWARD CHAIN. ???

No, in fact it is essential for many purposes.

1. The FTP data channel will be matched as RELATED to the initial control channel, so RELATED in FORWARD is needed if you are going to allow FTP.

2. ICMP error responses (usually seen in reply to UDP packets which fail for some reason) match as RELATED, and (as is already being discussed on another thread on this list), it is not a good idea to stop all ICMP packets from getting through your firewall.

There are other examples of why RELATED packets are necessary, but these are the most common and obvious ones.

You will generally find that all tutorials and netfilter examples match ESTABLISHED and RELATED in the FORWARD chain.

What makes you think that RELATED is dangerous?

Regards,

Antony.

Signature · 9 lines
The words "e pluribus unum" on the Great Seal of the United States are from
a
poem by Virgil entitled "Moretum", which is about cheese and garlic salad
dressing.

                                                     Please reply to the
list;
                                                           please don't CC
me.
#5 lore raw
Quoted 3 lines · Peter Marshall

You could make a connection out to a remote server. That remote server might try to make a connection back to us that has nothing to do with the reason we connected to them.

Such a connection would not be regarded as RELATED by the netfilter code.

Quoted 1 line

But the server may see it as related and allow it.

I think you should read about netfilter's definition of RELATED. It doesn't
just mean "any packet which comes back from an IP address we're already talking to".

For example, I said that FTP data connections were RELATED to the FTP control connection - but that is only if you have loaded the FTP Conntrack Helper
module, or compiled FTP Conntrack support into your kernel. That helper is
what RELATEs the two parts of FTP together in netfilter.

Basically, if you don't have a helper module which understands why a connection should be RELATED to another one, then it won't be.

Arbitrary packets from IP addresses which happen to be part of an ESTABLISHED connection don't count - they will be seen as NEW incoming connections, and make their own way through your ruleset (until they are persumably DROPped), having no assiciation whatever to anything else which may be in your connection tracking table.

Hope this clarifies things?

Regards,

Antony.

Signature · 4 lines
Ramdisk is not an installation procedure.

                                                     Please reply to the list;
                                                           please don't CC me.
#6 lore raw

yes it does. Thank you very much. I have been looking for an explanation like that on the net. :)

Do you have a link to where this netfilter documentation is ?

Peter

----- Original Message -----
From: "Antony Stone" <[email protected]>
To: "netfilter" <[email protected]>
Sent: Wednesday, June 30, 2004 2:07 PM
Subject: Re: track bandwith used

Quoted 3 lines · Peter Marshall

You could make a connection out to a remote server. That remote server might try to make a connection back to us that has nothing to do with the reason we connected to them.

Such a connection would not be regarded as RELATED by the netfilter code.

Quoted 1 line

But the server may see it as related and allow it.

I think you should read about netfilter's definition of RELATED. It
doesn't
just mean "any packet which comes back from an IP address we're already talking to".

For example, I said that FTP data connections were RELATED to the FTP control
connection - but that is only if you have loaded the FTP Conntrack Helper
module, or compiled FTP Conntrack support into your kernel. That helper is
what RELATEs the two parts of FTP together in netfilter.

Basically, if you don't have a helper module which understands why a connection should be RELATED to another one, then it won't be.

Arbitrary packets from IP addresses which happen to be part of an ESTABLISHED
connection don't count - they will be seen as NEW incoming connections, and make their own way through your ruleset (until they are persumably DROPped), having no assiciation whatever to anything else which may be in your connection tracking table.

Hope this clarifies things?

Regards,

Antony.

Signature · 6 lines
Ramdisk is not an installation procedure.

                                                     Please reply to the
list;
                                                           please don't CC
me.
#7 lore raw
Quoted 4 lines · Peter Marshall

yes it does. Thank you very much. I have been looking for an explanation like that on the net. :)

Do you have a link to where this netfilter documentation is ?

These might help fill in a few more details:

http://iptables-tutorial.frozentux.net/iptables-tutorial.html#USERLANDSTATES
http://www.sns.ias.edu/~jns/security/iptables/iptables_conntrack.html

Antony.

Quoted 41 lines

----- Original Message -----
From: "Antony Stone" <[email protected]>
To: "netfilter" <[email protected]>
Sent: Wednesday, June 30, 2004 2:07 PM
Subject: Re: track bandwith used

Quoted 3 lines · Peter Marshall

You could make a connection out to a remote server. That remote server might try to make a connection back to us that has nothing to do with the reason we connected to them.

Such a connection would not be regarded as RELATED by the netfilter code.

Quoted 1 line

But the server may see it as related and allow it.

I think you should read about netfilter's definition of RELATED. It
doesn't
just mean "any packet which comes back from an IP address we're already talking to".

For example, I said that FTP data connections were RELATED to the FTP control
connection - but that is only if you have loaded the FTP Conntrack Helper
module, or compiled FTP Conntrack support into your kernel. That helper
is what RELATEs the two parts of FTP together in netfilter.

Basically, if you don't have a helper module which understands why a connection should be RELATED to another one, then it won't be.

Arbitrary packets from IP addresses which happen to be part of an ESTABLISHED
connection don't count - they will be seen as NEW incoming connections, and make their own way through your ruleset (until they are persumably DROPped), having no assiciation whatever to anything else which may be in your connection tracking table.

Hope this clarifies things?

Regards,

Antony.

Signature · 6 lines
The truth is rarely pure, and never simple.

 - Oscar Wilde

                                                     Please reply to the list;
                                                           please don't CC me.
#8 lore raw

MRTG is very good for monitoring bandwidth utiliization, web interface is very cool it shows your inbound and outbound traffic graphically.

http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
is a good place learning about MRTG and
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg-unix-guide.html

is a very nice walk through to install and configure mrtg on unix, linux

regards

Quoted 68 lines · Antony Stone
Quoted 4 lines · Peter Marshall

yes it does. Thank you very much. I have been looking for an explanation like that on the net. :)

Do you have a link to where this netfilter documentation is ?

These might help fill in a few more details:

http://iptables-tutorial.frozentux.net/iptables-tutorial.html#USERLANDSTATES
http://www.sns.ias.edu/~jns/security/iptables/iptables_conntrack.html

Antony.

Quoted 41 lines

----- Original Message -----
From: "Antony Stone" <[email protected]>
To: "netfilter" <[email protected]>
Sent: Wednesday, June 30, 2004 2:07 PM
Subject: Re: track bandwith used

Quoted 3 lines · Peter Marshall

You could make a connection out to a remote server. That remote server might try to make a connection back to us that has nothing to do with the reason we connected to them.

Such a connection would not be regarded as RELATED by the netfilter code.

Quoted 1 line

But the server may see it as related and allow it.

I think you should read about netfilter's definition of RELATED. It
doesn't
just mean "any packet which comes back from an IP address we're already talking to".

For example, I said that FTP data connections were RELATED to the FTP control
connection - but that is only if you have loaded the FTP Conntrack Helper
module, or compiled FTP Conntrack support into your kernel. That helper
is what RELATEs the two parts of FTP together in netfilter.

Basically, if you don't have a helper module which understands why a connection should be RELATED to another one, then it won't be.

Arbitrary packets from IP addresses which happen to be part of an ESTABLISHED
connection don't count - they will be seen as NEW incoming connections, and make their own way through your ruleset (until they are persumably DROPped), having no assiciation whatever to anything else which may be in your connection tracking table.

Hope this clarifies things?

Regards,

Antony.

Signature · 8 lines
The truth is rarely pure, and never simple.

 - Oscar Wilde



                                                     Please reply to the list;
                                                           please don't CC me.