- Introduction
- System Architecture
- Prerequisites
- Installation
- Configuration
- SSL Configuration
- Troubleshooting
- Advanced Usage
- Contributing
- License
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.
graph TD
A[CoreDNS Server] -->|DNS Queries| B(Client VM 1)
A -->|DNS Queries| C(Client VM 2)
A -->|Fallback| D{Internet DNS 1.1.1.1}
B -->|SSL| E[Local Services]
C -->|SSL| E
- 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
-
Download and install CoreDNS:
wget https://github.com/coredns/coredns/releases/download/v1.10.1/coredns_1.10.1_linux_amd64.tgz tar xzf coredns_1.10.1_linux_amd64.tgz sudo mv coredns /usr/local/bin/
-
Verify installation:
coredns -version
On each client VM, edit the /etc/resolv.conf
file:
sudo nano /etc/resolv.conf
Add the following content (replace 192.168.1.10
with your CoreDNS server's IP):
nameserver 192.168.1.10
nameserver 1.1.1.1
Create and edit the Corefile:
sudo mkdir /etc/coredns
sudo nano /etc/coredns/Corefile
Add the following content:
.:53 {
hosts {
192.168.1.10 server.local
192.168.1.20 client1.local
192.168.1.30 client2.local
fallthrough
}
forward . 1.1.1.1
log
errors
}
Create a SystemD service file:
sudo nano /etc/systemd/system/coredns.service
Add the following content:
[Unit]
Description=CoreDNS DNS server
After=network.target
[Service]
ExecStart=/usr/local/bin/coredns -conf /etc/coredns/Corefile
Restart=on-failure
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable coredns
sudo systemctl start coredns
Generate a self-signed certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/hostname.local.key \
-out /etc/ssl/certs/hostname.local.crt
Follow the prompts, ensuring you set the Common Name to "hostname.local".
If CoreDNS fails to start, try the following:
-
Check permissions:
ls -l /usr/local/bin/coredns sudo chmod +x /usr/local/bin/coredns
-
Verify Corefile:
cat /etc/coredns/Corefile
-
Run CoreDNS manually:
sudo /usr/local/bin/coredns -conf /etc/coredns/Corefile
-
Check logs:
sudo journalctl -u coredns.service
-
Check for port conflicts:
sudo lsof -i :53
-
Configure firewall:
sudo firewall-cmd --permanent --add-service=dns sudo firewall-cmd --reload
- 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.
Implementing Custom SELinux Policy for CoreDNS
Step 1: Ensure SELinux is Enabled
First, make sure SELinux is in enforcing mode:
Step 2: Start CoreDNS and Generate Audit Logs
Start CoreDNS and let it run for a while to generate SELinux audit logs:
If CoreDNS fails to start, that's okay. We'll use the generated audit logs to create our policy.
Step 3: Analyze SELinux Audit Logs
Use the
ausearch
command to find CoreDNS-related SELinux denials:sudo ausearch -c 'coredns' --raw
Step 4: Generate a Custom SELinux Policy Module
Use
audit2allow
to generate a custom policy based on the audit logs:This command creates two files:
my-coredns.te
(Type Enforcement file) andmy-coredns.pp
(compiled policy package).Step 5: Review the Generated Policy
Examine the contents of
my-coredns.te
:Review the rules to ensure they make sense for CoreDNS operations. You may need to manually adjust this file if there are overly permissive rules.
Step 6: Apply the Custom Policy
Apply the new policy module:
Step 7: Set Correct File Contexts
Ensure CoreDNS files have the correct SELinux context:
Step 8: Configure SELinux Boolean for Network Access
Allow CoreDNS to access the network:
Step 9: Restart CoreDNS
Restart the CoreDNS service:
Step 10: Verify CoreDNS is Running
Check the status of CoreDNS:
If CoreDNS is running successfully, your SELinux policy is working correctly.
Step 11: Monitor for Further SELinux Denials
Continue to monitor SELinux logs for any new denials:
sudo ausearch -c 'coredns' --raw
If you see new denials, repeat steps 4-7 to refine your policy.
Troubleshooting
If you encounter issues:
sudo journalctl -u coredns
sudo cat /var/log/audit/audit.log | grep coredns
sudo setenforce 0
Remember to set it back to enforcing mode (
sudo setenforce 1
) after troubleshooting.By following these steps, you've created a custom SELinux policy that allows CoreDNS to function properly while maintaining the security benefits of SELinux.