Technical Discussion
  >> Linux Issues


Register (or login) on our website and you will not see this ad.


Pages in this thread: 1 | 2 | (show all)   Print Thread
Standard User think26872
(committed) Thu 07-Apr-11 20:20:28
Print Post

Help Select Bandwidth Monitor On Specific Ports For Ubuntu?


[link to this post]
 
Does anyone know of an application for Ubuntu that will log the amount of traffic going in/out presumingly over eth0 for a specific port (at least 80 and 443)?

e.g.

port / down / up
80 / 50MB / 5MB
443 / 1MB / 2MB
etc.

If it can split by date and time and other useful stuff better still.

TIA
Standard User john2007
(legend) Thu 07-Apr-11 20:31:47
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: think26872] [link to this post]
 
Try wireshark or tshark (not sure of the current name). I've only used it for short term monitoring though.
Standard User camieabz
(legend) Thu 07-Apr-11 20:54:06
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: john2007] [link to this post]
 
Can recommend wireshark (Windows). Not used it on unix though.

~~~~~~~~~~



© Camieabz 2002-2011 - All rights and lefts reserved.

report this link


Register (or login) on our website and you will not see this ad.

Standard User john2007
(legend) Thu 07-Apr-11 22:29:31
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: camieabz] [link to this post]
 
It's the same application. On Debian it needs some configuration to get it working as non root. May not be a problem on Ubuntu, or the OP may be happy/need to run as root.
Standard User mixt
(experienced) Thu 07-Apr-11 23:14:54
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: think26872] [link to this post]
 
You can use iptables. Add specific rules:

iptables -A INPUT -i eth0 -p tcp --sport 80 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT

Then use the commands:

iptables -vL INPUT
iptables -vL OUTPUT

This will give you some verbose information about the number of packets which matched the rules and the number of bytes transferred for the rules. Use:

iptables -vxL INPUT
iptables -vxL OUTPUT

to get iptables to give you the byte count only in bytes, regardless of the magnitude of the number of bytes matched (if you omit -x, it will output bytes in Kilo,Mega,Giga etc).

This is by far your easiest option. smile

EDIT: Use iptables -Z to zero ALL counters on ALL chains, or:

iptables -Z INPUT
iptables -Z OUTPUT

on only specific chains.

Now on <aaisp.net>
Previous ISPs: Virgin Media (50Mb/Cable), Be* Un Limited, ZeN
Is Linux routing your internet connection?
Need to make BIND geo-aware?

Edited by mixt (Thu 07-Apr-11 23:18:25)

Standard User think26872
(committed) Fri 08-Apr-11 19:36:23
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: mixt] [link to this post]
 
Thanks for all the answers.

I have given the iptables solution a try mainly to try to capture output via a script but it appears iptables always needs to be run as root.

Is it possible to run iptables as a normal user so I do not need to use sudo and add iptables to my sudoers file so it will work in scripts without it prompting for a password?

Thanks
Standard User troffasky
(newbie) Fri 08-Apr-11 21:45:01
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: think26872] [link to this post]
 
Yes, you always need to be root to use iptables [or just use sudo]. If you're not bothered about security you could make iptables setuid root with
Text
1
chmod +s `which /sbin/iptables`

which means that iptables will be run as root no matter who runs it.

For a quick realtime view, I suggest iptraf, iftop or [not quite so quick] ntop.

There are about trillion different half-written IP accounting systems for Linux, with any luck you might find one that works smile
Standard User mixt
(experienced) Fri 08-Apr-11 21:46:25
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: think26872] [link to this post]
 
iptables needs to run as root as it chats to the iptables / netfiltering module within the kernel. So for any iptables operation (adding rules or just listing rules within chains), you'll need to be root. Best bet is as you suggest - add it as an allowable sudo command.

To be honest, I tend to run any scripts like what your describing as root anyway. You could have one script which writes the information to a file somewhere (running as root) and then another script which comes in and reads the information from that file (not running as root) - a bit of a hack, but will work. If you're feeling frivolous, use a named pipe instead and have a script open the pipe as a file and let it feed output dynamically to it when ever something latches onto the named pipe to read from it - but that's not something I'm going to go into detail here in this post.

Now on <aaisp.net>
Previous ISPs: Virgin Media (50Mb/Cable), Be* Un Limited, ZeN
Is Linux routing your internet connection?
Need to make BIND geo-aware?
Standard User john2007
(legend) Sat 09-Apr-11 08:16:40
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: think26872] [link to this post]
 
Given your normal account access to iptables using sudoers sounds like the proper approach. Any particular reason you don't want to do that?
Standard User think26872
(committed) Sat 09-Apr-11 17:03:07
Print Post

Re: Help Select Bandwidth Monitor On Specific Ports For Ubun


[re: mixt] [link to this post]
 
Thanks. I think I will go with sudoers and iptables it seems the most suited to incorporate into a script.
Pages in this thread: 1 | 2 | (show all)   Print Thread

Jump to