Skip to content
Home ยป Configuring DNS Clients

Configuring DNS Clients

Configuring DNS Clients in Linux


1. Introduction

A DNS client is a system that sends queries to a DNS server to resolve domain names into IP addresses.
Configuring a DNS client means telling the system which DNS server to use for name resolution.

๐Ÿ‘‰ Example:
When you type www.google.com, the DNS client contacts a DNS server to get its IP address.


2. How DNS Client Works

  1. User enters a domain name
  2. DNS client checks local cache
  3. If not found โ†’ queries DNS server
  4. DNS server returns IP address
  5. System connects to the destination

3. DNS Client Configuration Methods


1. Using /etc/resolv.conf (Basic Method)

This is the main DNS configuration file.

Edit File

sudo vi /etc/resolv.conf

Example Configuration

nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com

Explanation

  • nameserver โ†’ DNS server IP
  • search โ†’ default domain suffix

๐Ÿ“Œ Multiple nameservers can be added (used in order).


2. Using Network Manager (Modern Systems)

On modern Linux systems (Ubuntu, Fedora), DNS is managed by NetworkManager.

Edit via CLI

nmcli con show
nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8"
nmcli con up "Wired connection 1"

3. Using Netplan (Ubuntu Server)

Edit Netplan File

sudo vi /etc/netplan/01-netcfg.yaml

Example

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Apply:

sudo netplan apply

4. Using DHCP (Automatic DNS Configuration)

  • DNS servers are automatically assigned
  • Configured via DHCP server

๐Ÿ“Œ Suitable for:

  • Home networks
  • Dynamic environments

4. Local DNS Configuration

Edit /etc/hosts

sudo vi /etc/hosts

Example

192.168.1.10   example.com

๐Ÿ“Œ Used for:

  • Local name resolution
  • Testing DNS without server

5. Testing DNS Client Configuration


Using ping

ping google.com

Using nslookup

nslookup google.com

Using dig

dig google.com

6. DNS Client Configuration Flow

User Request
   โ†“
Local Cache (/etc/hosts)
   โ†“
DNS Resolver (/etc/resolv.conf)
   โ†“
DNS Server
   โ†“
IP Address Returned

7. Important Files

FilePurpose
/etc/resolv.confDNS servers
/etc/hostsLocal mapping
/etc/nsswitch.confLookup order

8. Common Issues & Troubleshooting

IssueSolution
DNS not resolvingCheck /etc/resolv.conf
Wrong IPVerify DNS server
Slow DNSChange to faster DNS
Conflict with NetworkManagerRestart service

9. Best Practices

  • Use reliable DNS servers (Google: 8.8.8.8)
  • Configure backup DNS servers
  • Avoid manual changes if managed by DHCP
  • Use /etc/hosts only for testing

10. Real-World Example

  • Office network:
    • DNS server: 192.168.1.1
  • Client configuration:
nameserver 192.168.1.1

11. Conclusion

Configuring DNS clients in Linux ensures proper domain name resolution and network communication. With tools like /etc/resolv.conf, Netplan, and NetworkManager, Linux provides flexible and efficient DNS client configuration, essential for both desktop and server environments.