Okay, let's break down the best DNS server choice and the configuration steps for your scenario. Given your requirements of:
- Local DDNS: Workstations need to be able to update their
*.office.internal records.
- No DHCP: You're managing IP assignments statically or through another DHCP server.
.office.internal Zone: Authoritative for your internal domain.
- Upstream Resolution: Resolve other domains (e.g.,
*.com, *.net) via dns.usc.edu.
- Lightweight and Easy: Ease of setup and low resource usage are important.
Best Choice: dnsmasq
dnsmasq is an excellent fit for this. Here's why:
- Lightweight: Designed for small networks.
- Easy to Configure: Simple configuration file format.
- DDNS Support: Supports dynamic updates.
- Conditional Forwarding: Can forward requests for specific domains to specific upstream servers.
- Can Act as a DNS Server Only: Doesn't force you to use its DHCP server.
Configuration Steps (Ubuntu/Debian-based example):
-
Install dnsmasq:
sudo apt update
sudo apt install dnsmasq
-
Configure dnsmasq: The primary configuration file is usually /etc/dnsmasq.conf. You'll likely want to start by backing up the original file:
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
Then, edit /etc/dnsmasq.conf (using sudo nano /etc/dnsmasq.conf or your preferred editor). Here's a suggested configuration:
# Listen only on the interface connected to the local network.
# Replace 'eth0' with the correct interface name if needed.
interface=eth0
listen-address=127.0.0.1,192.168.1.1 # Replace 192.168.1.1 with the static IP of your DNS server
bind-interfaces
# Define the local domain and reverse DNS range
domain=office.internal
local=/office.internal/
# Upstream DNS server for external domains
server=/!office.internal/dns.usc.edu # Forward queries not ending in office.internal to dns.usc.edu
# Enable dynamic DNS updates
# This assumes updates come from the local network. Adjust the range if needed.
# Enable this line if you want to accept secure updates using the `nsupdate` tool.
# The "local" modifier means updates are only allowed from the local network.
# These secure update options can be used if you set up `dnssec-keygen`.
#tsig-keygen=office.internal
#local-service-key=/etc/dnsmasq.d/office.internal.key
#auth-server=office.internal,192.168.1.1 #Replace with your static DNS server IP
#auth-peer=office.internal
# Enable secure dynamic updates, which may be useful for your situation. If not needed, comment it out.
# Uncomment the following line to enable this.
#dhcp-script=/etc/dnsmasq.d/ddns_update.sh
# Log queries (optional, but useful for troubleshooting)
log-queries
# Prevent dnsmasq from reading resolv.conf, which may contain public DNS servers.
no-resolv
Important Notes within the Configuration:
interface=: Replace eth0 with the correct network interface on your server that's connected to your local network. You can find this with ip addr or ifconfig.
listen-address=: Replace 192.168.1.1 with the static IP address of the server you're configuring as the DNS server. This tells dnsmasq to listen on that specific address. You must have a static IP address assigned to this server. Keep 127.0.0.1 in this line so that you can also run dns query locally.
domain=: Sets the domain name for the local network.
local=/office.internal/: Tells dnsmasq to treat .office.internal as a local domain.
server=/!office.internal/dns.usc.edu: This line is the critical one for conditional forwarding. It tells dnsmasq to forward any queries not ending in .office.internal to the specified upstream DNS server (dns.usc.edu).
dhcp-script=/etc/dnsmasq.d/ddns_update.sh This can be enabled to allow secure dynamic updates via the nsupdate tool. If enabled, the ddns_update.sh script must be implemented.
no-resolv: This line prevents dnsmasq from reading and using the system's /etc/resolv.conf file. This ensures that dnsmasq only uses the upstream DNS servers you've explicitly configured, like dns.usc.edu. This is essential for controlling DNS resolution.
-
Create the Update Script (Optional): /etc/dnsmasq.d/ddns_update.sh
This allows secure updates via nsupdate tool.
#!/bin/sh
# Extract parameters passed by dnsmasq
hostname="$DNSMASQ_HOSTNAME"
domain="$DNSMASQ_DOMAIN"
ip_address="$DNSMASQ_ADDRESS"
interface="$DNSMASQ_INTERFACE"
fqdn="$hostname.$domain"
# Log the update request
logger "DDNS Update Request: hostname=$hostname, domain=$domain, ip=$ip_address, interface=$interface"
# Check if the script is run with correct user (root or user with sudo privileges)
if [ "$(id -u)" -ne "0" ]; then
logger "DDNS Update: Script must be run as root."
exit 1
fi
# Check if the FQDN is within the allowed domain
if [[ "$fqdn" != *".office.internal" ]]; then
logger "DDNS Update: Invalid domain: $fqdn"
exit 1
fi
# Construct the update command (adjust based on your actual DNS server)
nsupdate_cmd=$(cat <<EOF
server 127.0.0.1 # Or the IP address of your DNS server if not local
update delete $fqdn A
update add $fqdn 300 A $ip_address
send
EOF
)
# Execute the update using nsupdate
echo "$nsupdate_cmd" | nsupdate
# Check the result
if [ $? -ne 0 ]; then
logger "DDNS Update failed for $fqdn"
else
logger "DDNS Update successful for $fqdn to $ip_address"
fi
exit 0
Make the script executable:
sudo chmod +x /etc/dnsmasq.d/ddns_update.sh
Important Notes within the Update Script:
server 127.0.0.1: This tells nsupdate to communicate with the local DNS server. Adjust if your DNS server isn't running on the same machine.
update delete $fqdn A: This removes any existing A record for the FQDN.
update add $fqdn 300 A $ip_address: This adds the new A record with a TTL of 300 seconds (adjust as needed).
nsupdate: You likely need to install bind9-utils (or the equivalent package for your distribution) to get the nsupdate tool: sudo apt install bind9-utils
-
Restart dnsmasq:
sudo systemctl restart dnsmasq
-
Configure Workstations:
- DNS Server Address: On each workstation, set the DNS server address to the static IP address of the server where you installed
dnsmasq (e.g., 192.168.1.1 in the example). This is done through the workstation's network settings. Do not configure the workstations to use DHCP for DNS settings.
- Hostname: Ensure each workstation has a unique hostname. The hostname, combined with the
office.internal domain, will be its fully qualified domain name (FQDN). You usually set the hostname during the operating system installation or through system settings.
- DDNS Update Script/Command (Optional): The simplest way to update via the
nsupdate tool is described in the next section.
Dynamic DNS Updates with nsupdate (Recommended)
This is the most robust way to handle dynamic updates.
-
Install bind9-utils (if not already installed):
sudo apt update
sudo apt install bind9-utils
-
Create a DDNS Update Script on each client: (Adjust paths as needed)
#!/bin/bash
# Get the hostname and create the FQDN
hostname=$(hostname)
domain="office.internal" # Ensure this matches your dnsmasq config
fqdn="$hostname.$domain"
# Get the current IP address
ip_address=$(ip addr show eth0 | grep "inet " | awk '{print $2}' | cut -d'/' -f1) # Change 'eth0' if needed
# Construct the nsupdate command
nsupdate_cmd=$(cat <<EOF
server 192.168.1.1 # Replace with your DNS server IP
update delete $fqdn A
update add $fqdn 300 A $ip_address
send
EOF
)
# Execute the update using nsupdate
echo "$nsupdate_cmd" | nsupdate
# Check the result
if [ $? -ne 0 ]; then
echo "DDNS Update failed for $fqdn"
exit 1
else
echo "DDNS Update successful for $fqdn to $ip_address"
fi
exit 0
- Make the script executable:
chmod +x /path/to/ddns_update.sh
- Adjust
eth0 if needed to the correct interface.
- Replace
192.168.1.1 with the static IP address of your DNS server.
-
Run the Script:
-
Run the script manually whenever the IP address changes.
-
Set up a cron job to run it periodically (e.g., every 5 minutes) to catch IP changes automatically:
crontab -e
Add a line like this (adjust the path):
*/5 * * * * /path/to/ddns_update.sh >/dev/null 2>&1
Testing
-
On the DNS Server:
-
Check the dnsmasq logs (usually /var/log/syslog or /var/log/daemon.log) for any errors or update messages.
-
Use nslookup or dig to query dnsmasq:
nslookup workstation1.office.internal 192.168.1.1 #Replace workstation1 with actual workstation name, and replace the IP if it's different from 192.168.1.1
-
On Workstations:
-
Use nslookup or dig to query the workstation's own IP address, or the IP address of a workstation on the local network:
nslookup workstation1.office.internal
The result should return the IP address of workstation1.
-
Try resolving an external domain:
nslookup google.com
This should resolve to a public Google IP address, meaning the upstream forwarding is working.
Important Considerations:
- Security: Without a secure update mechanism (TSIG, as mentioned in the
dnsmasq.conf comments), anyone on your network could potentially update DNS records. Consider using TSIG for authentication if security is a concern.
- IP Address Stability: Dynamic DNS works best when IP addresses don't change too frequently. If workstations are constantly changing IP addresses, frequent updates can become problematic.
- Error Handling: The update scripts should include robust error handling (logging, retries) to deal with temporary network issues.
This comprehensive setup should provide a functional and relatively easy-to-manage local DDNS system using dnsmasq. Remember to adapt the configuration examples to your specific network environment (interface names, IP addresses, paths, etc.). Good luck!