-1

I have a server which keeps on receiving request from two other servers from different IP ranges. I need to know how can I setup a cronjob which keeps on checking number of connection made by each server every second and keep on updating the result in a txt file.

1 Answers1

0
while true; do netstat -punta | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort -n | uniq -c | sort -n; sleep 1; done

Can't use cron though. Should load it through systemd or something.


You probably want something like this though:

iptables -A INPUT -m tcp -p tcp -m state --state NEW -j LOG --log-prefix "New Connection"

From there you can start controlling what is going on with contrack. https://unix.stackexchange.com/questions/139285/limit-max-connections-per-ip-address-and-new-connections-per-second-with-iptable

It's really not clear what your actual problem is, but if you ask that instead of trying to do what ever you are trying to do, we might be able to help out more.

Daniel Widrick
  • 3,488
  • 2
  • 13
  • 27