mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 07:47:07 +00:00
Add scripts to automatically update the LAN DNS records.
./sbin/update-dns.sh may be called at regular intervals (one hour or so) via crontab. It will automatically detect: - its local host name (*.lan.dougal.aaltronav.eu); and - which IP has internet access, if any. Armed with that information and with the dynamic DNS API password stored in DYNDNS_PASSWD in ~/.dougalrc, it will update the relevant DNS record. For this to work, the first `lan.dougal` hostname in the Nginx configuration must be the one that is set up for dynamic update. Other `lan.dougal` hostnames should be CNAME records pointing to the first one.
This commit is contained in:
19
sbin/get-ip.sh
Executable file
19
sbin/get-ip.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Find the interface used for the default route (e.g., to reach 8.8.8.8)
|
||||
INTERFACE=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++) if ($i=="dev") {print $(i+1); exit}}')
|
||||
|
||||
if [ -z "$INTERFACE" ] || [ "$INTERFACE" = "lo" ]; then
|
||||
echo "No valid default route found." >/dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the primary IPv4 address from the interface (excluding loopback)
|
||||
IP=$(ip -4 addr show dev "$INTERFACE" scope global | grep -oP '(?<=inet\s)\d{1,3}(\.\d{1,3}){3}(?=/)' | head -n1)
|
||||
|
||||
if [ -z "$IP" ]; then
|
||||
echo "No global IPv4 address found on $INTERFACE." >/dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$IP"
|
||||
Reference in New Issue
Block a user