DNS Configuration

Understanding DNS configuration through /etc/resolv.conf, nameserver setup, and DNS resolution troubleshooting

DNS Configuration with /etc/resolv.conf

Topic Overview

The /etc/resolv.conf file configures DNS resolution for Linux systems. It tells the system which DNS servers to query when converting domain names to IP addresses, making it critical for network connectivity and internet access.

Key Concepts

  • Name Resolution: Converting hostnames to IP addresses
  • DNS Server: Server that translates domain names to IPs
  • Search Domain: Default domain appended to hostnames
  • Resolver: System component that performs DNS lookups
  • Nameserver Priority: Order servers are queried

File Structure

1
2
3
4
nameserver IP_ADDRESS
search domain.com
domain domain.com
options option_name
  • Each directive on separate line
  • Comments start with #
  • Changes take effect immediately

Common Directives

nameserver - DNS server IP address (max 3) search - List of domains for hostname completion
domain - Local domain name (deprecated) options - Resolver behavior modifications

Practical Examples

Example 1: Basic configuration

1
2
3
nameserver 8.8.8.8
nameserver 8.8.4.4
search company.com

Uses Google DNS with company domain search

Example 2: View current config

1
cat /etc/resolv.conf

Displays current DNS configuration

Example 3: Test DNS resolution

1
2
nslookup google.com
dig @8.8.8.8 example.com

Verify DNS is working correctly

Example 4: Backup before editing

1
2
sudo cp /etc/resolv.conf /etc/resolv.conf.bak
sudo nano /etc/resolv.conf

Always backup before making changes

Common Options

timeout:n - Query timeout in seconds attempts:n - Number of query attempts rotate - Round-robin through nameservers ndots:n - Dots needed to try absolute name first

Use Cases

  • Configure corporate DNS servers
  • Set up local network resolution
  • Troubleshoot connectivity issues
  • Override DHCP-provided DNS settings
  • Set up split DNS configurations

nslookup - Interactive DNS lookup tool dig - Detailed DNS information utility host - Simple DNS lookup command
systemd-resolve - Modern systemd DNS tool resolvectl - Control systemd-resolved

Tips & Troubleshooting

Common Issues

  • File gets overwritten: Network Manager or DHCP may reset changes. Use chattr +i to make immutable or configure through Network Manager

  • DNS not working: Check if systemd-resolved is managing DNS instead of resolv.conf

  • Slow resolution: Add options single-request to avoid IPv6 lookup delays

Best Practices

  • Use at least 2 nameservers for redundancy
  • Put fastest/most reliable server first
  • Keep search list short (max 6 domains)
  • Monitor for automatic overwrites

Security Notes

  • Avoid untrusted DNS servers
  • Consider DNS over HTTPS/TLS
  • Monitor for DNS hijacking attempts
  • Use internal DNS for local resources