Monitoramento Contínuo de Rede com MTR e Bash

Listen to this Post

Manter a conectividade estável é essencial para qualquer infraestrutura de TI. Para garantir isso, desenvolvi um script Bash que executa testes automáticos com MTR (My Traceroute), analisando latência e perdas de pacotes a cada 15 segundos e registrando tudo em um log!

✅ O que esse script faz?

🔹 Monitora a rota até um destino IP/Domínio.

🔹 Identifica saltos instáveis e perda de pacotes.

🔹 Gera logs automáticos para análise posterior.

🔹 Executa testes continuamente a cada 15 segundos.

🛠️ Como Usar?

1️⃣ Instale o MTR no Linux:

sudo apt update && sudo apt install mtr -y  Ubuntu/Debian 
sudo yum install mtr -y  CentOS/RHEL 

2️⃣ Baixe o Script no GitHub:

git clone https://github.com/felipebrasilio/monitoramento-mtr.git 
cd monitoramento-mtr 

3️⃣ Torne o Script Executável:

chmod +x monitor_mtr.sh 

4️⃣ Execute o Monitoramento:

./monitor_mtr.sh 

📂 Código completo disponível no GitHub:

🔗 Acesse aqui

You Should Know:

1. Understanding MTR (My Traceroute)

MTR combines `traceroute` and `ping` to provide real-time network diagnostics. Key flags:

mtr -r -c 10 google.com  Send 10 reports and stop 
mtr --report-wide -c 50 8.8.8.8  Wide output for 50 packets 

2. Automating Log Analysis with Bash

Extend the script to parse logs for anomalies:

grep "Loss%" mtr_log.txt | awk '{if ($3 > 10) print "High packet loss at: "$1}' 

3. Scheduling with Cron

Run the script periodically via `cron`:

crontab -e 
/30     /path/to/monitor_mtr.sh >> /var/log/mtr_monitor.log 

4. Alternative Tools

  • PingPlotter: Graphical traceroute for Windows.
  • SmokePing: Latency monitoring with alerts.
  • Netdata: Real-time network dashboard.

5. Network Debugging Commands

ip route show  Check routing table 
ss -tulnp  List active connections (modern netstat) 
tcptrack -i eth0  Monitor TCP traffic 
nmap -sn 192.168.1.0/24  Ping sweep a subnet 

What Undercode Say:

Continuous network monitoring is critical for identifying bottlenecks, ISP issues, or cyberattacks. MTR provides granular insights, but combining it with tools like `iftop` (bandwidth monitoring) or `Wireshark` (packet analysis) enhances visibility. For enterprises, integrate with SIEMs like Graylog or ELK Stack for centralized logging. Always validate scripts from GitHub before execution (less monitor_mtr.sh).

Pro Tip: Use `jq` to parse JSON logs if the script outputs structured data:

cat mtr_log.json | jq '.report.hubs[] | select(.LossPct > 5)' 

Expected Output:

Start time: 2025-03-31 10:00:00 
Target: google.com 
Hop IP Loss% Avg Latency 
1 192.168.1.1 0% 2.1ms 
2 10.10.10.1 5% 15.3ms 
... 

🔗 References:

References:

Reported By: Felipebrasilio Github – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image