How to Fix CoreDNS Forward Proxy Configuration Error
In this tutorial, you'll learn about How to Fix CoreDNS Forward Proxy Configuration Error. We cover key concepts, practical examples, and best practices.
CoreDNS forward plugin returns SERVFAIL or queries time out when forwarding to external DNS servers — the forward targets are unreachable or configured incorrectly.
The Problem
$ dig @localhost google.com
;; status: SERVFAIL
# CoreDNS logs
[ERROR] plugin/forward: Failed to connect to "8.8.8.8:53":
dial tcp 8.8.8.8:53: i/o timeout
Step-by-Step Fix
Step 1: Configure forward plugin correctly
data:
Corefile: |
.:53 {
errors
health
kubernetes cluster.local
forward . 8.8.8.8 1.1.1.1 {
max_concurrent 1000
policy random
health_check 5s
}
cache 30
}
Step 2: Configure conditional forwarding
data:
Corefile: |
.:53 {
kubernetes cluster.local
forward . 8.8.8.8
}
internal.example.com:53 {
errors
forward . 192.168.1.10:53 {
health_check 5s
}
}
Step 3: Test upstream connectivity
kubectl run dns-test --image=busybox --rm -it --restart=Never -- \
nslookup google.com 8.8.8.8
Step 4: Check forward policy
# Available policies
forward . 8.8.8.8 1.1.1.1 {
policy random # Random selection (default)
# policy round_robin # Sequential
# policy sequential # Try first, then second
# policy first # Always use first
}
Step 5: Add timeout settings
forward . 8.8.8.8 {
expire 30s
max_fails 3
tls_servername dns.google
}
Prevention Tips
- Use multiple forward targets for redundancy
- Enable health checks on forward targets
- Set
max_concurrentto avoid resource exhaustion - Monitor forward plugin metrics for failure rates
Common Mistakes with forward proxy
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging
These mistakes appear frequently in real-world COREDNS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro