5

Is there any package to install with apt to detect if the Server has no Internet connection and output maybe a netstat to a file if so?
My problem is: I have a Server and since today it randomly has no Internet for hours. I don't know if it's a DDoS or something different and I want to find out. I also can only SSH into it so it needs Internet to let me do anything.
(It's just a fun project so there is really only me who could do something)

Comments
  • 1
    Okay our hoster has a Problem and they are fixing it. But still, does anyone know a package like this?
  • 1
    Use cronjob to run a script that attempts some connection to something and logs failures ?
  • 0
    you can easily script things like that. Do you have root? What BASH version is in there? what's the OS?

    [oh right, you've mentioned apt. So it's gotta be *buntu]
  • 3
    #!/bin/bash

    LOG_FILE="/tmp/outages.log";
    PROBE_ADDR="googlesss.com";
    PROBE_PORT="80";

    result=$(nc -w 2 -vz "${PROBE_ADDR}" "${PROBE_PORT}" 2>&1) ;
    failed=${?};

    date >>"${LOG_FILE}";
    echo "${result}" >>"${LOG_FILE}";

    if [[ ${failed} -eq 1 ]] ; then
    uptime >>"${LOG_FILE}";
    route -n >>"${LOG_FILE}";
    ifconfig -a >>"${LOG_FILE}";
    ifconfig | awk '/Link/ {print $1}' | while read nic; do
    ethtool ${nic} >>"${LOG_FILE}";
    done;
    nslookup "${PROBE_ADDR}" >>"${LOG_FILE}";
    ping -c3 "${PROBE_ADDR}" >>"${LOG_FILE}";
    traceroute "${PROBE_ADDR}" >>"${LOG_FILE}";
    netstat -ntpla >>"${LOG_FILE}";

    :;
    printf "========================================\n\n" >>"${LOG_FILE}";
    fi;

    You can wrap this in a loop. Or add the script to cron to be triggered every x minutes.

    Edit settings ofc with your probe inet address/port and log file address. Make sure you have all those tools installed
  • 1
    ALSO have a look at dmesg output. And /var/log/{syslog,kern.log}. These are quite likely to suggest what has happened
  • 0
Add Comment