To set up a local Dynamic DNS (DDNS) server for your office's local network with the requirements you've outlined, dnsmasq is an excellent choice. It is lightweight, easy to configure, and supports both local domain resolution and forwarding queries to upstream DNS servers.
Why dnsmasq?
- Lightweight: Dnsmasq is designed to be simple and efficient, making it ideal for small to medium-sized networks.
- Local Domain Resolution: You can define local domains like
*.office.internal directly in the configuration.
- Upstream DNS Forwarding: Queries for domains outside of your local scope (e.g.,
dns.usc.edu) can be forwarded to an external DNS server.
- Dynamic DNS Support: Dnsmasq can integrate with scripts or DHCP servers to update DNS records dynamically.
Step-by-Step Configuration
1. Install dnsmasq
On most Linux distributions, you can install dnsmasq using the package manager:
# For Debian/Ubuntu:
sudo apt update
sudo apt install dnsmasq
# For CentOS/RHEL:
sudo yum install dnsmasq
2. Configure dnsmasq
The main configuration file for dnsmasq is typically located at /etc/dnsmasq.conf. Edit this file to meet your requirements.
sudo nano /etc/dnsmasq.conf
Add or modify the following lines:
# Define the local domain
local=/office.internal/
# Resolve *.office.internal to specific IPs (optional)
address=/workstation1.office.internal/192.168.1.10
address=/workstation2.office.internal/192.168.1.11
# Forward all other queries to the upstream DNS server
server=/dns.usc.edu/8.8.8.8
# Listen on the local network interface (replace eth0 with your network interface)
interface=eth0
# Disable DHCP functionality (since you don't want to serve DHCP)
no-dhcp-interface=eth0
# Optional: Enable logging for debugging purposes
log-queries
log-facility=/var/log/dnsmasq.log
3. Configure Dynamic DNS Updates (Optional)
If you want to support dynamic DNS updates (e.g., when workstations change their IP addresses), you can use a script to update the DNS records dynamically. Dnsmasq does not natively support DDNS updates, but you can achieve this by integrating it with a custom script.
For example, create a script /usr/local/bin/update-dns.sh:
#!/bin/bash
# Update DNS record for a workstation
HOSTNAME=$1
IP=$2
# Update the dnsmasq hosts file
echo "$IP $HOSTNAME.office.internal" > /etc/hosts.dnsmasq
# Reload dnsmasq to apply changes
sudo systemctl reload dnsmasq
Make the script executable:
sudo chmod +x /usr/local/bin/update-dns.sh
Then, configure your workstations to call this script whenever their IP address changes.
4. Start and Enable dnsmasq
Start the dnsmasq service and enable it to start on boot:
sudo systemctl start dnsmasq
sudo systemctl enable dnsmasq
5. Test the Configuration
-
Query a local domain:
nslookup workstation1.office.internal
This should return the IP address you configured (e.g., 192.168.1.10).
-
Query an external domain:
nslookup dns.usc.edu
This should forward the query to the upstream DNS server and return the correct result.
6. Configure Clients
Ensure that all workstations in your office network are configured to use the IP address of the machine running dnsmasq as their primary DNS server. For example, if the dnsmasq server has the IP 192.168.1.1, configure the DNS settings on each workstation to point to this address.
Additional Notes
- Security: If your network is accessible from the internet, consider restricting access to the dnsmasq server to only your local network by using firewall rules.
- Logging: The
log-queries option is useful for debugging but can generate a lot of logs. Disable it once everything is working correctly.
- Scalability: For larger networks, consider using a more robust DNS server like BIND, but for your use case, dnsmasq is sufficient.
This setup should meet your requirements for a lightweight, easy-to-configure local DDNS server. Let me know if you need further clarification or assistance!