diff --git a/Dockerfile b/Dockerfile
index 135fe27..014a86e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \
inetutils-traceroute \
nano \
openssl \
+ dnsutils \
&& rm -rf /var/lib/apt/lists/*
# those are the really necessary packages
diff --git a/console/views.py b/console/views.py
index 5ce6a37..b8d59cf 100644
--- a/console/views.py
+++ b/console/views.py
@@ -46,6 +46,9 @@ def view_console(request):
elif requested_command == 'traceroute':
page_title = 'Console: traceroute ' + command_target
bash_command = ['bash', '-c', 'traceroute ' + command_target]
+ elif requested_command == 'testdns':
+ page_title = 'Console: DNS container test script'
+ bash_command = ['/app/dns/scripts/test_dns_service.sh']
else:
bash_command = None
command_output = ''
diff --git a/dns/scripts/test_dns_service.sh b/dns/scripts/test_dns_service.sh
new file mode 100755
index 0000000..761b5b0
--- /dev/null
+++ b/dns/scripts/test_dns_service.sh
@@ -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"
\ No newline at end of file
diff --git a/dns/views.py b/dns/views.py
index b11c68a..349e31d 100644
--- a/dns/views.py
+++ b/dns/views.py
@@ -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/')
diff --git a/templates/console/console.html b/templates/console/console.html
index a08e43e..4b3a7f0 100644
--- a/templates/console/console.html
+++ b/templates/console/console.html
@@ -18,6 +18,7 @@
route -n
traceroute
ping
+ dns test