How to know traffic to a specific port in linux
Asked Answered
M

2

10

I am looking to find the traffic through a specific port for a time frame. For example, traffic through 3306 port for 10 seconds. Is there a way to find this information?

I see that "/sbin/ifconfig eth0 05" can be used to get information on total bytes but I am looking to find information about specific port's traffic.

Thanks in advance,

Manlove answered 10/5, 2012 at 14:39 Comment(3)
Did you look at tcpdump (tcpdump.org/tcpdump_man.html)?Journalize
What information do you need? Amount of traffic, who is connected - what?Sulphonate
Unless you try to do that through programming, this kind of question does not belong here.Bed
B
25
tcpdump -i eth0 -s 1500 port 3306
Beadsman answered 10/5, 2012 at 14:42 Comment(6)
I tried tcpdump but there doesn't seem to be a way to monitor the port for certain amount of time (like 5 seconds). @Jenny D: I am looking for amount of traffic for a port for certain time period.Manlove
Just use another process to send tcpdump a signal after 5 seconds. Or make your own program using libpcap.Sandra
Thanks. I guess I can make the program 'sleep' for 5 seconds and use the same tcpdump command again.Manlove
@Beadsman : What if I want to see the raw-data sent over port 3306 ?Ptyalin
Use the 'src' parameter and set it to your local IP addressBeadsman
You can use the 'watch' command to do exactly what you want. Essentially 'watch -n 5 tcpdump -i eth0 -s 1500 port 3306'. See linux.die.net/man/1/watch.Selfinduction
B
5
sudo iftop -P -n -N -m 10M -f 'port 3260'
  • -P display ports
  • -n no hostname lookup
  • -N display ports not service names
  • -m limit for bandwidth scale
  • -f filter rule
Baseball answered 7/4, 2018 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.