#!/bin/bash # Port Forwarding Test Script # Tests if port 5006 is accessible from external networks echo "==========================================" echo "Port Forwarding Test for WebDAV (Port 5006)" echo "==========================================" echo "" # Get external IP echo "1. Checking external IP address..." EXTERNAL_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s icanhazip.com 2>/dev/null) if [ -z "$EXTERNAL_IP" ]; then echo "❌ Unable to determine external IP" else echo "✅ External IP: $EXTERNAL_IP" fi echo "" # Get internal IP echo "2. Checking internal IP address..." if command -v ip &> /dev/null; then INTERNAL_IP=$(ip route get 8.8.8.8 2>/dev/null | grep -oP 'src \K\S+' | head -1) elif command -v hostname &> /dev/null; then INTERNAL_IP=$(hostname -I | awk '{print $1}') fi if [ -z "$INTERNAL_IP" ]; then echo "⚠️ Unable to determine internal IP" else echo "✅ Internal IP: $INTERNAL_IP" fi echo "" # Test local port echo "3. Testing local port 5006..." if command -v nc &> /dev/null; then if timeout 2 nc -zv localhost 5006 2>&1 | grep -q "succeeded"; then echo "✅ Port 5006 is open locally" else echo "❌ Port 5006 is NOT open locally" echo " → Service may not be running or bound incorrectly" fi else echo "⚠️ netcat not available, skipping local test" fi echo "" # Test internal network port if [ -n "$INTERNAL_IP" ]; then echo "4. Testing internal network access..." if command -v nc &> /dev/null; then if timeout 2 nc -zv "$INTERNAL_IP" 5006 2>&1 | grep -q "succeeded"; then echo "✅ Port 5006 accessible from internal network" else echo "❌ Port 5006 NOT accessible from internal network" echo " → Service may be bound to localhost only" fi fi fi echo "" # Test external port (if external IP service available) echo "5. Testing external port accessibility..." echo " (This requires an external service - may not work in all environments)" if command -v nc &> /dev/null && [ -n "$EXTERNAL_IP" ]; then echo " Attempting to test from external perspective..." echo " Note: This test may not work if your network blocks outbound connections" echo "" echo " Manual test recommended:" echo " From a device outside your network, run:" echo " telnet $EXTERNAL_IP 5006" echo " or" echo " nc -zv $EXTERNAL_IP 5006" fi echo "" # Port forwarding checklist echo "6. Port Forwarding Configuration Checklist" echo "-------------------------------------------" echo "On your router, ensure:" echo "" echo " External Port: 5006" echo " Internal IP: $INTERNAL_IP (your NAS IP)" echo " Internal Port: 5006" echo " Protocol: TCP" echo "" echo " Status: [ ] Configured" echo "" # Firewall checklist echo "7. Firewall Configuration Checklist" echo "-------------------------------------------" echo "On your NAS/router:" echo " [ ] Port 5006 allowed in firewall" echo " [ ] Incoming connections on port 5006 allowed" echo " [ ] Service bound to 0.0.0.0:5006 (not 127.0.0.1:5006)" echo "" echo "==========================================" echo "Next Steps" echo "==========================================" echo "" echo "If local test fails:" echo " 1. Check if WebDAV service is running" echo " 2. Check service configuration (Listen directive)" echo "" echo "If local test passes but internal fails:" echo " 1. Service is likely bound to localhost only" echo " 2. Change Listen/ServerName to 0.0.0.0:5006" echo "" echo "If internal test passes but external fails:" echo " 1. Check router port forwarding configuration" echo " 2. Check router firewall settings" echo " 3. Verify ISP is not blocking port 5006" echo ""