DNS diagnostic tool

This commit is contained in:
Eduardo Silva
2024-07-09 14:46:59 -03:00
parent 99ca031645
commit 070c99b433
8 changed files with 50 additions and 4 deletions

33
dns/scripts/test_dns_service.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
echo '--- Ping the DNS container...'
ping -c 4 wireguard-webadmin-dns
echo ''
echo ''
echo '--- Checking firewall rules...'
iptables -t nat -L WGWADM_PREROUTING -nv |grep -e pkts -e dpt:53
output=$(iptables -t nat -L WGWADM_PREROUTING -nv | grep -e dpt:53)
if [[ -z "$output" ]]; then
echo ''
echo '=== ERROR: No firewall rules redirecting the DNS service were found.'
else
if [[ "$output" == *"127.0.0.250"* ]]; then
echo ''
echo '=== ERROR: The firewall script failed to resolve the DNS service name.'
echo '=== The IP 127.0.0.250 is a fallback address.'
fi
fi
echo ''
echo ''
echo '--- Testing the DNS resolution...'
echo 'Resolving google.com...'
dig @wireguard-webadmin-dns google.com +short
echo ''
echo ''
echo '--- Testing getent hosts...'
getent hosts wireguard-webadmin-dns
DNS_IP=$(getent hosts wireguard-webadmin-dns | awk '{ print $1 }')
if [ -z "$DNS_IP" ]; then
DNS_IP="127.0.0.250"
fi
echo "DNS IP: $DNS_IP"

View File

@@ -8,14 +8,19 @@ from .functions import generate_dnsmasq_config
from django.conf import settings
@login_required
def view_apply_dns_config(request):
def export_dns_configuration():
dns_settings, _ = DNSSettings.objects.get_or_create(name='dns_settings')
dns_settings.pending_changes = False
dns_settings.save()
dnsmasq_config = generate_dnsmasq_config()
with open(settings.DNS_CONFIG_FILE, 'w') as f:
f.write(dnsmasq_config)
return
@login_required
def view_apply_dns_config(request):
export_dns_configuration()
messages.success(request, 'DNS settings applied successfully')
return redirect('/dns/')