-
Notifications
You must be signed in to change notification settings - Fork 0
VPN Monitoring
Comprehensive guide to the VPN monitoring system, DNS leak detection capabilities, and status tracking features.
SafeHarbor includes a sophisticated monitoring system that:
- Continuously monitors VPN connection status
- Detects DNS leaks automatically using multiple methods
- Tracks IP changes and location information
- Sends real-time alerts via Telegram
- Provides detailed logging for troubleshooting
ββββββββββββββββββββββββββββββββββββββββββ
β VPN Network β
β βββββββββββββββββββββββββββββββββββββββ
β β Keepalive Client ββ
β β (Inside VPN Tunnel) ββ
β β ββ
β β β’ Gathers VPN IP info ββ
β β β’ Tests DNS resolution ββ
β β β’ Detects location changes ββ
β β β’ Sends status to server ββ
β βββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββ
β
β HTTP POST /keepalive
βΌ
ββββββββββββββββββββββββββββββββββββββββββ
β Host Network β
β βββββββββββββββββββββββββββββββββββββββ
β β Keepalive Server ββ
β β (Real IP Network) ββ
β β ββ
β β β’ Receives client data ββ
β β β’ Compares with previous state ββ
β β β’ Sends Telegram notifications ββ
β β β’ Provides status API ββ
β βββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββ
The system tracks multiple VPN parameters:
Connection Status:
- VPN gateway connectivity
- Public IP address and changes
- Geographic location (country, region, city)
- ISP information
- Connection uptime
Network Health:
- DNS resolution testing
- Latency measurements
- Bandwidth availability
- Service accessibility
Every 5 minutes (configurable), the client:
- Gathers VPN Information:
# External IP detection
curl -s https://ipinfo.io/json
# DNS location testing
curl -s https://1.1.1.1/cdn-cgi/trace
# Provider information
# Geographic location data- Performs Health Checks:
# Test connectivity to various services
curl -s https://httpbin.org/ip
curl -s https://icanhazip.com- Sends Status Report:
{
"client_id": "synology-vpn-media",
"timestamp": "2025-10-12T15:30:15Z",
"public_ip": "185.170.104.53",
"location": {
"country": "PL",
"region": "Kujawsko-Pomorskie",
"city": "ToruΕ"
},
"dns_status": "secure",
"provider": "AS50599 DATASPACE P.S.A."
}A DNS leak occurs when DNS queries bypass the VPN tunnel and use your ISP's DNS servers, potentially exposing:
- Websites you visit
- Your real location
- Browsing patterns
- Service usage
SafeHarbor uses multiple detection techniques:
# Get VPN server location
VPN_COUNTRY=$(curl -s https://ipinfo.io/json | jq -r '.country')
# Get DNS resolver location
DNS_COUNTRY=$(curl -s https://1.1.1.1/cdn-cgi/trace | grep '^loc=' | cut -d'=' -f2)
# Compare locations
if [ "$VPN_COUNTRY" != "$DNS_COUNTRY" ]; then
echo "DNS LEAK DETECTED: VPN=$VPN_COUNTRY, DNS=$DNS_COUNTRY"
fi# Check configured DNS servers
cat /etc/resolv.conf
# Should show VPN DNS (usually 127.0.0.1 for Gluetun)
# nameserver 127.0.0.1
# NOT your ISP's DNS servers like:
# nameserver 8.8.8.8
# nameserver 1.1.1.1# Use external DNS leak detection services
curl -s "https://bash.ws/dnsleak"
# Multiple endpoint testing
curl -s "https://ipleak.net/json/"Normal Operation (No Leak):
β
Keepalive sent successfully at Sun Oct 12 10:50:27 UTC 2025
π Location: ToruΕ, Kujawsko-Pomorskie, PL
π VPN IP: 185.170.104.53
π DNS: PL (WAW) - No leak detected
DNS Leak Detected:
β οΈ Keepalive sent with DNS LEAK at Sun Oct 12 10:55:30 UTC 2025
π Location: ToruΕ, Kujawsko-Pomorskie, PL
π VPN IP: 185.170.104.53
π DNS: US (LAX) - LEAK DETECTED!
Telegram Alert for DNS Leak:
π DNS LEAK DETECTED! π
Client: synology-vpn-media
Time: 2025-10-12 15:25:10 (Europe/Madrid)
VPN Location: Poland (PL)
DNS Location: United States (US)
β οΈ Your DNS requests may be exposed!
VPN Disconnection:
- Triggered when client fails to report for >5 minutes
- Immediate notification with real IP detection
- Includes location and ISP information
VPN Restoration:
- Sent when client reconnects after being offline
- Confirms VPN protection is restored
- Includes new VPN server information
IP Address Changes:
π VPN IP ADDRESS CHANGED π
Client: synology-vpn-media
Time: 2025-10-12 16:15:30 (Europe/Madrid)
Previous IP: 185.170.104.53 (Poland)
New IP: 185.72.199.129 (Poland)
Location: ToruΕ, Kujawsko-Pomorskie, PL
DNS Status: Secure (no leak detected)
Location Changes:
π VPN LOCATION CHANGED π
Client: synology-vpn-media
Previous: Poland, ToruΕ
New: Netherlands, Amsterdam
IP: 91.236.55.128
Time: 2025-10-12 16:20:15 (Europe/Madrid)
No Clients Reporting:
β οΈ NO VPN CLIENTS REPORTING β οΈ
Time: 2025-10-12 15:40:00 (Europe/Madrid)
Last client seen: 8 minutes ago
Status: All clients appear offline
Check your VPN containers immediately!
# Timing settings in .env
ALERT_THRESHOLD_MINUTES=5 # Alert delay
CHECK_INTERVAL_MINUTES=5 # Check frequency
# Notification settings
TELEGRAM_BOT_TOKEN=your_token
TELEGRAM_CHAT_ID=your_chat_id# Check current VPN IP and location
docker exec gluetun wget -qO- https://ipinfo.io/json
# Expected VPN response:
{
"ip": "185.170.104.53",
"city": "ToruΕ",
"region": "Kujawsko-Pomorskie",
"country": "PL",
"org": "AS50599 DATASPACE P.S.A.",
"timezone": "Europe/Warsaw"
}
# Check if it matches your real location (should NOT match)
curl -s https://ipinfo.io/json # From host (should show real IP)# Method 1: Compare VPN and DNS locations
VPN_COUNTRY=$(docker exec gluetun wget -qO- https://ipinfo.io/json | grep country | cut -d'"' -f4)
DNS_COUNTRY=$(docker exec gluetun wget -qO- https://1.1.1.1/cdn-cgi/trace | grep '^loc=' | cut -d'=' -f2)
echo "VPN Country: $VPN_COUNTRY, DNS Country: $DNS_COUNTRY"
# Should match if no leak (e.g., both show "PL")
# LEAK if different (e.g., VPN="PL", DNS="US")
# Method 2: Check DNS servers in use
docker exec gluetun cat /etc/resolv.conf
# Should show Gluetun DNS:
# nameserver 127.0.0.1
# Method 3: External leak test
docker exec gluetun wget -qO- "https://bash.ws/dnsleak"# Test container connectivity through VPN
docker exec qbittorrent curl -s http://localhost:9117 # Jackett
docker exec sonarr curl -s https://ipinfo.io/ip # Should show VPN IP
# Test VPN gateway health
docker exec gluetun wget -qO- http://localhost:9999/health
# Monitor VPN logs in real-time
docker logs gluetun --followSuccessful Operation:
π Starting continuous VPN monitoring loop...
π Gathering VPN information...
β
Keepalive sent successfully at Sun Oct 12 10:50:27 UTC 2025
π Location: ToruΕ, Kujawsko-Pomorskie, PL
π VPN IP: 185.170.104.53
π’ Provider: AS50599 DATASPACE P.S.A.
π Timezone: Europe/Warsaw
π DNS: PL (WAW) - No leak detected
β³ Waiting 300 seconds until next keepalive...
Connection Problems:
β Failed to send keepalive to http://duevite.eu:5421 at Sun Oct 12 10:46:01 UTC 2025
π Location: Unknown, Unknown, Unknown
π VPN IP: unknown
π’ Provider: Unknown
π DNS: Unknown
Normal Operation:
π API Access: keepalive | IP: 10.51.0.1 | Auth: WITH_KEY | Status: 200_OK
Keepalive received from synology-vpn-media - IP: 185.170.104.53
β
Telegram message sent successfully
π Monitoring check: 1 client(s) registered
Alert Triggers:
β οΈ Client synology-vpn-media is offline (7 minutes since last contact)
π€ VPN disconnection alert sent to Telegram
β
Telegram message sent successfully
Healthy VPN Connection:
INFO [firewall] allowing VPN connection...
INFO [openvpn] OpenVPN 2.6.11 x86_64-alpine-linux-musl
INFO [openvpn] Initialization Sequence Completed
INFO [healthcheck] healthy!
INFO [ip getter] Public IP address is 185.170.104.53 (Poland, ToruΕ)
INFO [dns] DNS server listening on [::]:53
INFO [dns] ready
# Faster alerting (2 minutes)
ALERT_THRESHOLD_MINUTES=2
# More frequent checking (every 2 minutes)
CHECK_INTERVAL_MINUTES=2
# Less sensitive (10 minutes)
ALERT_THRESHOLD_MINUTES=10
CHECK_INTERVAL_MINUTES=10The server can track multiple VPN clients:
# Different client configurations
CLIENT_ID=home-server # Client 1
CLIENT_ID=office-vpn # Client 2
CLIENT_ID=mobile-client # Client 3Multi-client status:
π VPN Status
π’ home-server - Online
IP: 185.170.104.53 (Poland)
Last seen: 1 minute ago
π’ office-vpn - Online
IP: 91.236.55.128 (Netherlands)
Last seen: 2 minutes ago
π΄ mobile-client - Offline
Last seen: 8 minutes ago
The monitoring server provides REST API endpoints:
# Get server status
curl -s http://localhost:5421/status | jq
# Get detailed client information
curl -s http://localhost:5421/clients | jq
# Health check endpoint
curl -s http://localhost:5421/health# API key protection for keepalive endpoints
KEEPALIVE_API_KEY=your-secure-random-key
# Rate limiting (30 requests per minute per IP)
MAX_REQUESTS_PER_MINUTE=30
# IP whitelisting (optional)
ALLOWED_IPS=10.51.0.1,192.168.1.100- VPN Network: Media containers + keepalive client
- Monitoring Network: Keepalive server (isolated)
- No cross-network communication except via API
- No sensitive data logged (only IP geolocation)
- Telegram communications encrypted (HTTPS)
- Local data only (no external data collection)
Next Steps:
- Troubleshooting - If monitoring isn't working properly
- Telegram Bot - Setting up notifications
- Architecture - Understanding the technical implementation