Managing name resolution through /etc/hosts
files across multiple workstations is tedious and error-prone, especially when:
- New internal services get added frequently
- Client project domains change often
- Team members use different operating systems
We need a solution that:
1. Serves custom internal records (wiki.os, projects.client1.os)
2. Forwards external queries to upstream DNS
3. Runs reliably on Debian
4. Requires minimal maintenance
Instead of full BIND setup, dnsmasq provides perfect middle ground:
sudo apt install dnsmasq
Configuration (/etc/dnsmasq.conf
):
# Enable DNS functionality
port=53
# Local domain suffix
local=/os/
# Static host entries
address=/wiki.os/192.168.1.10
address=/icons.os/192.168.1.10
address=/projects.client1.os/192.168.1.11
# Forward external queries
server=8.8.8.8
server=8.8.4.4
On your DHCP server (usually router):
- Set primary DNS to your Debian server's IP
- Keep secondary DNS as router or public DNS
Or manually on clients:
sudo nano /etc/resolv.conf
nameserver 192.168.1.10 # Your Debian server
nameserver 192.168.1.1 # Router fallback
For dynamic environments, consider:
# Wildcard subdomains
address=/*.dev.os/192.168.1.20
# Hosts file integration
addn-hosts=/etc/dnsmasq.hosts
# Regular expression matching
mx-host=os,mx.os,10
After restarting dnsmasq (sudo systemctl restart dnsmasq
):
nslookup wiki.os
dig +short projects.client1.os
# Check query forwarding
dig example.com
Automate DNS records updates with this bash script:
#!/bin/bash
# update_dns.sh
NEW_IP=$(hostname -I | awk '{print $1}')
echo "address=/newservice.os/$NEW_IP" >> /etc/dnsmasq.d/dynamic.conf
systemctl reload dnsmasq
Managing multiple development environments through /etc/hosts files across an office network is indeed painful. Every time we add a new project (like client1.os or api.os), we need to:
# Example of messy hosts management
192.168.1.100 wiki.os
192.168.1.100 git.os
192.168.1.100 staging.clientx.os
# And 20 more entries...
Instead of BIND (which is overkill), we'll use dnsmasq - a lightweight DNS forwarder that perfectly handles local overrides while forwarding other queries to your upstream DNS.
Key benefits:
- Local hostname resolution with automatic network-wide propagation
- Maintains single source of truth on server
- DHCP integration (optional)
- Under 5MB memory footprint
First, install dnsmasq on your Debian server:
sudo apt update
sudo apt install dnsmasq
Configure /etc/dnsmasq.conf:
# Enable DNS server
port=53
# Local domain
local=/os/
# Add custom host entries
address=/wiki.os/192.168.1.100
address=/icons.os/192.168.1.100
# Forward all other requests to Google DNS
server=8.8.8.8
server=8.8.4.4
On each client machine, change DNS settings to point to your server's IP. For Debian/Ubuntu clients:
sudo nano /etc/resolvconf/resolv.conf.d/head
# Add:
nameserver 192.168.1.100
# Then:
sudo resolvconf -u
For development environments where you need *.dev.os to resolve to your server:
address=/.dev.os/192.168.1.100
Test your setup using dig or nslookup:
dig wiki.os @192.168.1.100
nslookup icons.os 192.168.1.100
For real-time monitoring:
sudo tail -f /var/log/syslog | grep dnsmasq
Keep your DNS entries manageable using includes:
conf-dir=/etc/dnsmasq.d/,*.conf
Then create separate files in /etc/dnsmasq.d/:
# projects.conf
address=/project1.os/192.168.1.100
address=/project2.os/192.168.1.100
# clients.conf
address=/clientA.os/192.168.1.101
address=/clientB.os/192.168.1.102