Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
CoreDNS Setup for Local Network with SSL#
Table of Contents#
Introduction#
This project sets up a local DNS infrastructure using CoreDNS, with one Debian server acting as the DNS server and two client VMs. The system is designed to use CoreDNS for local hostname resolution and fall back to 1.1.1.1 for internet queries. Additionally, it includes SSL configuration for secure local connections.
System Architecture#
The setup consists of:
- 1 Debian VM running CoreDNS as the DNS server
- 2 Client VMs configured to use the CoreDNS server
- SSL certificates for secure local connections
- Fallback to Cloudflare DNS (1.1.1.1) for external queries
Prerequisites#
- 1 Debian VM for CoreDNS server
- 2 Client VMs (any Linux distribution)
- Root or sudo access on all VMs
- Basic understanding of DNS and networking
Installation#
CoreDNS Server Setup#
- Download and install CoreDNS:
1wget https://github.com/coredns/coredns/releases/download/v1.10.1/coredns_1.10.1_linux_amd64.tgz2tar xzf coredns_1.10.1_linux_amd64.tgz3sudo mv coredns /usr/local/bin/- Verify installation:
1coredns -versionClient VM Configuration#
On each client VM, edit the /etc/resolv.conf file:
1sudo nano /etc/resolv.confAdd the following content (replace 192.168.1.10 with your CoreDNS server’s IP):
1nameserver 192.168.1.102nameserver 1.1.1.1Configuration#
CoreDNS Configuration File#
Create and edit the Corefile:
1sudo mkdir /etc/coredns2sudo nano /etc/coredns/CorefileAdd the following content:
1.:53 {2 hosts {3 192.168.1.10 server.local4 192.168.1.20 client1.local5 192.168.1.30 client2.local6 fallthrough7 }8 forward . 1.1.1.19 log10 errors11}SystemD Service Setup#
Create a SystemD service file:
1sudo nano /etc/systemd/system/coredns.serviceAdd the following content:
1[Unit]2Description=CoreDNS DNS server3After=network.target4
5[Service]6ExecStart=/usr/local/bin/coredns -conf /etc/coredns/Corefile7Restart=on-failure8
9[Install]10WantedBy=multi-user.targetEnable and start the service:
1sudo systemctl daemon-reload2sudo systemctl enable coredns3sudo systemctl start corednsSSL Configuration#
Generate a self-signed certificate:
1sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \2 -keyout /etc/ssl/private/hostname.local.key \3 -out /etc/ssl/certs/hostname.local.crtFollow the prompts, ensuring you set the Common Name to “hostname.local”.
Troubleshooting#
If CoreDNS fails to start, try the following:
- Check permissions:
1ls -l /usr/local/bin/coredns2sudo chmod +x /usr/local/bin/coredns- Verify Corefile:
1cat /etc/coredns/Corefile- Run CoreDNS manually:
1sudo /usr/local/bin/coredns -conf /etc/coredns/Corefile- Check logs:
1sudo journalctl -u coredns.service- Check for port conflicts:
1sudo lsof -i :53- Configure firewall:
1sudo firewall-cmd --permanent --add-service=dns2sudo firewall-cmd --reloadAdvanced Usage#
- Custom DNS records: Add more entries to the hosts section in the Corefile.
- Plugins: CoreDNS supports various plugins. Explore the official documentation for more options.
Conclusion#
This setup provides a robust local DNS solution with SSL support, perfect for development environments and homelabs. The CoreDNS server handles local hostname resolution while maintaining internet connectivity through Cloudflare DNS.