DNS Configuration and Troubleshooting
Understand how Linux servers resolve hostnames to IP addresses: configure resolvers, edit /etc/hosts, and use dig, nslookup, and host to diagnose DNS problems that break connectivity even when the network is fine.
DNS Configuration and Troubleshooting is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why DNS Matters on a Server
Your server can have perfect network and firewall settings yet still fail to reach the outside world if it cannot resolve names. DNS translates human-friendly hostnames like example.com into IP addresses.
Knowing how resolution works — and how to debug it — is essential network skill.
The Resolution Path
When a program needs an IP for a name, Linux checks sources in order, typically:
- The local
/etc/hostsfile - Configured DNS servers (resolvers)
The order is governed by /etc/nsswitch.conf on the hosts: line.
grep hosts /etc/nsswitch.conf
# hosts: files dnsThe /etc/hosts File
/etc/hosts maps names to IPs locally, bypassing DNS. It is perfect for testing, internal hostnames, or pinning a domain to a specific IP.
Each line is an IP followed by one or more names.
127.0.0.1 localhost
192.168.1.50 db.internal dbWhere Resolvers Are Configured
The classic file is /etc/resolv.conf, which lists nameservers. On modern systems it is often managed by systemd-resolved or NetworkManager, so editing it directly may not stick.
Check what is actually in use before changing anything.
cat /etc/resolv.conf
resolvectl statusSetting a DNS Server
On a systemd-resolved system, set DNS per interface rather than editing resolv.conf. On Netplan-based servers you define it in the YAML config.
This example sets public resolvers for an interface.
sudo resolvectl dns eth0 1.1.1.1 8.8.8.8
resolvectl dns eth0Looking Up Records with dig
dig is the most powerful DNS query tool. It shows the answer plus query metadata.
The +short option strips it down to just the answer — ideal for scripts.
dig example.com
dig +short example.comQuerying Specific Record Types
DNS stores many record types. Specify one to inspect mail, name servers, or aliases.
A— IPv4 addressAAAA— IPv6 addressMX— mail serversNS— name serversCNAME— alias
dig example.com MX +short
dig example.com NS +shortnslookup and host
nslookup and host are simpler alternatives to dig. They are handy for quick checks and a reverse lookup (IP to name).
Reverse lookups query the PTR record for an address.
host example.com
nslookup example.com
dig -x 8.8.8.8 +shortQuerying a Specific Server
To test whether one resolver is the problem, point a query at a specific server with the @ syntax. If a public resolver works but yours does not, the issue is your DNS config.
dig @1.1.1.1 example.com +short
dig @8.8.8.8 example.com +shortA Troubleshooting Workflow
When a name will not resolve, work through layers:
- Can you ping an IP directly? (rules out network)
- Does
dig @1.1.1.1 namework? (rules out the name itself) - Does
dig namewith your default resolver work? (isolates resolver config) - Is there a stale
/etc/hostsentry overriding it?
ping -c1 1.1.1.1
dig @1.1.1.1 example.com +short
dig example.com +shortBest Practices
Keep name resolution reliable:
- Use at least two resolvers for redundancy
- Do not hand-edit
resolv.confif it is auto-managed - Use
/etc/hostsfor testing, but clean up stale entries - Prefer
dig +shortin scripts for clean output
Quick Check
Test your DNS troubleshooting knowledge.
Recap
You can now configure and debug DNS on a server:
- Resolution order via
/etc/nsswitch.confand/etc/hosts - Resolvers in
resolv.conf/systemd-resolved - Querying with
dig,host,nslookup, including specific record types and servers - A layered troubleshooting workflow
This complements your network and firewall skills with the naming layer.
Frequently asked questions
Is the “DNS Configuration and Troubleshooting” lesson free?
Yes — the full text of “DNS Configuration and Troubleshooting” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.
What will I learn in “DNS Configuration and Troubleshooting”?
Understand how Linux servers resolve hostnames to IP addresses: configure resolvers, edit /etc/hosts, and use dig, nslookup, and host to diagnose DNS problems that break connectivity even when the ne… You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Server Deployment & SSH Mastery?
No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “DNS Configuration and Troubleshooting” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?
Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Basic Network Configuration
- Understanding Firewalls (UFW/firewalld)
- Port Management & Security
- DNS Configuration and Troubleshooting