Initial commit: combine nas_tool, nas_webdav, sync-utils

This commit is contained in:
Gan, Jimmy
2026-02-18 22:59:43 +08:00
commit 526c6a5521
77 changed files with 7898 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
# NAS WebDAV External Access Troubleshooting
This repository contains diagnostic tools and guides to help troubleshoot WebDAV external access issues on NAS systems.
## Problem
WebDAV works on intranet but fails from external networks with "Connection refused" error.
## Quick Start
1. **Run the diagnostic script on your NAS:**
```bash
sudo ./diagnose_webdav.sh
```
2. **Check port forwarding:**
```bash
./check_port_forwarding.sh
```
3. **Review the troubleshooting guide:**
- See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for detailed solutions
## Files
- `diagnose_webdav.sh` - Comprehensive diagnostic script to check service binding, firewall, and configuration
- `check_port_forwarding.sh` - Tests port accessibility and provides port forwarding checklist
- `TROUBLESHOOTING.md` - Detailed troubleshooting guide with common issues and solutions
## Most Common Issues
1. **Service bound to localhost only** - Service listens on `127.0.0.1:5006` instead of `0.0.0.0:5006`
2. **Firewall blocking port** - Port 5006 not allowed in firewall rules
3. **Router port forwarding not configured** - External port 5006 not forwarded to NAS internal IP
4. **Router firewall blocking** - Router firewall blocking incoming connections
## Quick Fix
The most common fix is ensuring your WebDAV service is bound to all interfaces:
**Apache:**
```apache
Listen 0.0.0.0:5006
```
**Nginx:**
```nginx
listen 0.0.0.0:5006;
```
Then configure router port forwarding: External 5006 → Internal NAS IP:5006
## Usage
All scripts should be run on your NAS system:
```bash
# Make scripts executable (already done)
chmod +x *.sh
# Run diagnostics
sudo ./diagnose_webdav.sh
# Check port forwarding
./check_port_forwarding.sh
```
+164
View File
@@ -0,0 +1,164 @@
# WebDAV External Access Troubleshooting Guide
## Problem
WebDAV works on intranet but fails from external networks with "Connection refused" error.
## Common Causes and Solutions
### 1. Service Bound to Localhost Only
**Symptom:** Service only listens on `127.0.0.1` or `::1` instead of all interfaces.
**Solution:**
- **Apache:** Change `Listen 127.0.0.1:5006` to `Listen 0.0.0.0:5006` or `Listen *:5006`
- **Nginx:** Change `listen 127.0.0.1:5006;` to `listen 0.0.0.0:5006;` or `listen *:5006;`
- **Other services:** Ensure binding to `0.0.0.0` or `*` instead of `localhost`/`127.0.0.1`
**Check:**
```bash
netstat -tuln | grep 5006
# or
ss -tuln | grep 5006
```
If you see `127.0.0.1:5006` or `::1:5006`, the service is only accessible locally.
### 2. Firewall Blocking Port 5006
**Solution:**
**UFW (Ubuntu/Debian):**
```bash
sudo ufw allow 5006/tcp
sudo ufw reload
```
**firewalld (CentOS/RHEL):**
```bash
sudo firewall-cmd --permanent --add-port=5006/tcp
sudo firewall-cmd --reload
```
**iptables:**
```bash
sudo iptables -A INPUT -p tcp --dport 5006 -j ACCEPT
sudo iptables-save
```
### 3. Router Port Forwarding Not Configured
**Solution:**
1. Access your router's admin panel
2. Navigate to Port Forwarding / Virtual Server settings
3. Add rule:
- **External Port:** 5006
- **Internal IP:** Your NAS IP address (e.g., 192.168.1.100)
- **Internal Port:** 5006
- **Protocol:** TCP
4. Save and apply changes
### 4. Router Firewall Blocking Incoming Connections
**Solution:**
- Check router firewall settings
- Ensure port 5006 is allowed for incoming connections
- Some routers have separate WAN firewall rules
### 5. ISP Blocking Port 5006
**Solution:**
- Some ISPs block certain ports
- Try a different external port (e.g., 5007, 8080)
- Update port forwarding to use the new port
### 6. Service Not Running or Crashed
**Check service status:**
```bash
# For systemd services
systemctl status webdav
# or
systemctl status apache2
# or
systemctl status nginx
# Check if process is running
ps aux | grep -i webdav
```
**Restart service:**
```bash
sudo systemctl restart webdav
# or
sudo systemctl restart apache2
# or
sudo systemctl restart nginx
```
### 7. NAS-Specific Configuration
**Synology NAS:**
1. Control Panel → External Access → Router Configuration
2. Enable port forwarding for port 5006
3. Control Panel → Security → Firewall
4. Ensure port 5006 is allowed
**QNAP NAS:**
1. Network & Virtual Switch → Port Forwarding
2. Add rule for port 5006
3. Security → Firewall → Allow port 5006
**Other NAS:**
- Check NAS admin panel for port forwarding/firewall settings
- Ensure WebDAV service is enabled and configured for external access
## Diagnostic Steps
1. **Run the diagnostic script:**
```bash
chmod +x diagnose_webdav.sh
sudo ./diagnose_webdav.sh
```
2. **Test local connection:**
```bash
curl -k -X PROPFIND https://localhost:5006
# or
curl -k -X PROPFIND https://127.0.0.1:5006
```
3. **Test from internal network:**
```bash
curl -k -X PROPFIND https://<NAS_INTERNAL_IP>:5006
```
4. **Test from external network:**
```bash
curl -k -X PROPFIND https://jimmygan.myds.me:5006
```
5. **Check if port is reachable externally:**
```bash
# From external network
telnet jimmygan.myds.me 5006
# or
nc -zv jimmygan.myds.me 5006
```
## Quick Fix Checklist
- [ ] Service is bound to `0.0.0.0:5006` (not `127.0.0.1:5006`)
- [ ] Firewall allows port 5006
- [ ] Router port forwarding configured (External 5006 → Internal NAS IP:5006)
- [ ] Router firewall allows incoming connections on port 5006
- [ ] WebDAV service is running
- [ ] Tested local connection (works)
- [ ] Tested internal network connection (works)
- [ ] External connection still fails → Check ISP/port blocking
## Additional Notes
- **DDNS:** Your domain `jimmygan.myds.me` appears to be a DDNS service. Ensure it's properly configured and pointing to your current external IP.
- **HTTPS:** Since you're using HTTPS, ensure SSL certificate is valid and the service is configured for SSL/TLS.
- **IPv6:** The error shows IPv6 connection attempts. If your router/NAS doesn't support IPv6 properly, you may need to disable IPv6 or configure it separately.
+118
View File
@@ -0,0 +1,118 @@
#!/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 ""
+142
View File
@@ -0,0 +1,142 @@
#!/bin/bash
# WebDAV External Access Diagnostic Script
# This script helps diagnose why WebDAV is not accessible from external networks
echo "=========================================="
echo "WebDAV External Access Diagnostic Tool"
echo "=========================================="
echo ""
# Check if running as root (needed for some checks)
if [ "$EUID" -ne 0 ]; then
echo "⚠️ Some checks may require root privileges"
echo ""
fi
# 1. Check what's listening on port 5006
echo "1. Checking what's listening on port 5006..."
echo "-------------------------------------------"
if command -v netstat &> /dev/null; then
echo "Using netstat:"
netstat -tuln | grep 5006 || echo "❌ Nothing found listening on port 5006"
elif command -v ss &> /dev/null; then
echo "Using ss:"
ss -tuln | grep 5006 || echo "❌ Nothing found listening on port 5006"
else
echo "⚠️ netstat or ss not available"
fi
echo ""
# 2. Check if service is bound to localhost only
echo "2. Checking if service is bound to localhost only..."
echo "-------------------------------------------"
if command -v netstat &> /dev/null; then
netstat -tuln | grep 5006 | grep "127.0.0.1\|::1" && echo "❌ Service is bound to localhost only!" || echo "✅ Service is not bound to localhost only"
elif command -v ss &> /dev/null; then
ss -tuln | grep 5006 | grep "127.0.0.1\|::1" && echo "❌ Service is bound to localhost only!" || echo "✅ Service is not bound to localhost only"
fi
echo ""
# 3. Check if port 5006 is open in firewall
echo "3. Checking firewall status..."
echo "-------------------------------------------"
if command -v ufw &> /dev/null; then
echo "UFW Status:"
ufw status | grep 5006 || echo "⚠️ Port 5006 not found in UFW rules"
elif command -v firewall-cmd &> /dev/null; then
echo "firewalld Status:"
firewall-cmd --list-ports | grep 5006 || echo "⚠️ Port 5006 not found in firewalld rules"
elif command -v iptables &> /dev/null; then
echo "iptables rules for port 5006:"
iptables -L -n | grep 5006 || echo "⚠️ No iptables rules found for port 5006"
else
echo "⚠️ No common firewall tool detected"
fi
echo ""
# 4. Check WebDAV service status (common services)
echo "4. Checking WebDAV service status..."
echo "-------------------------------------------"
if systemctl list-units --type=service | grep -i webdav &> /dev/null; then
systemctl list-units --type=service | grep -i webdav | while read service; do
servicename=$(echo $service | awk '{print $1}')
echo "Service: $servicename"
systemctl status $servicename --no-pager | head -5
done
else
echo "⚠️ No WebDAV systemd service found"
echo "Checking common WebDAV processes:"
ps aux | grep -i webdav | grep -v grep || echo "No WebDAV processes found"
fi
echo ""
# 5. Test local connection
echo "5. Testing local connection to port 5006..."
echo "-------------------------------------------"
if command -v nc &> /dev/null; then
if nc -zv localhost 5006 2>&1; then
echo "✅ Local connection successful"
else
echo "❌ Local connection failed"
fi
else
echo "⚠️ netcat (nc) not available for connection test"
fi
echo ""
# 6. Check network interfaces
echo "6. Network interface information..."
echo "-------------------------------------------"
if command -v ip &> /dev/null; then
ip addr show | grep -E "^[0-9]+:|inet " | head -10
elif command -v ifconfig &> /dev/null; then
ifconfig | grep -E "^[a-z]|inet " | head -10
fi
echo ""
# 7. Check router/NAT configuration hints
echo "7. Router/NAT Configuration Checklist..."
echo "-------------------------------------------"
echo "Please verify on your router/NAS:"
echo " □ Port forwarding: External port 5006 → Internal NAS IP:5006"
echo " □ Firewall rules allow incoming connections on port 5006"
echo " □ NAT/UPnP is configured correctly"
echo " □ External IP matches: $(curl -s ifconfig.me 2>/dev/null || echo 'Unable to determine')"
echo ""
# 8. Common WebDAV configuration files to check
echo "8. Common WebDAV configuration locations..."
echo "-------------------------------------------"
config_locations=(
"/etc/apache2/sites-available/*webdav*"
"/etc/apache2/conf.d/*webdav*"
"/etc/nginx/sites-available/*webdav*"
"/etc/nginx/conf.d/*webdav*"
"/etc/lighttpd/lighttpd.conf"
"/etc/httpd/conf.d/*webdav*"
"/usr/local/etc/apache2/*webdav*"
)
for pattern in "${config_locations[@]}"; do
for file in $pattern; do
if [ -f "$file" ]; then
echo "Found: $file"
echo " Checking for Listen/ServerName directives..."
grep -E "Listen|ServerName|<VirtualHost|listen" "$file" | head -3 || true
fi
done
done
echo ""
echo "=========================================="
echo "Diagnostic Complete"
echo "=========================================="
echo ""
echo "Common Issues and Solutions:"
echo "1. If service is bound to 127.0.0.1: Change Listen directive to 0.0.0.0:5006"
echo "2. If firewall blocks port: Open port 5006 in firewall"
echo "3. If router blocks: Configure port forwarding for port 5006"
echo "4. If service not running: Start the WebDAV service"
echo ""