109.4 Configure client side

Tech Tutorial: 109.4 Configure client-side DNS #

Introduction #

DNS (Domain Name System) is crucial in the networking realm as it translates human-memorable domain names (like www.example.com) into IP addresses that networking equipment need for routing packets. Configuring DNS properly on a client host is essential for efficient network communication and resource access. This tutorial will guide you through the steps to configure DNS on a Linux client system.

Key Knowledge Areas #

  • Understand the /etc/resolv.conf file
  • Use of systemd-resolved
  • Configure DNS with NetworkManager
  • Test DNS configuration

Utilities #

  • resolvconf
  • nmcli
  • systemd-resolve
  • dig
  • nslookup

Step-by-Step Guide #

1. Understanding /etc/resolv.conf #

Before diving into configuration, it’s important to understand the /etc/resolv.conf file. This file is used by the resolver library to determine the DNS servers that the system uses for name resolution. Here is a typical example:

# /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8
search example.com

Each nameserver line specifies a DNS server to use. The search line is used to set the domain search list.

2. Using resolvconf to Manage DNS Information #

resolvconf is a utility on some Linux distributions to manage /etc/resolv.conf. When installed, you should avoid editing /etc/resolv.conf directly, as resolvconf will overwrite your changes. Here’s how to add a new DNS server:

echo "nameserver 8.8.4.4" | sudo resolvconf -a eth0.inet

To view the current DNS configurations managed by resolvconf:

resolvconf --show

3. Configure DNS using systemd-resolved #

On systems using systemd-networkd, DNS resolution is often handled by systemd-resolved. To use this service, you can link /etc/resolv.conf to the systemd-resolved managed symlink:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

To add or change the DNS servers:

sudo systemd-resolve --set-dns=9.9.9.9 --interface=eth0
sudo systemd-resolve --set-dns=149.112.112.112 --interface=eth0

To verify DNS configuration:

systemd-resolve --status

4. Configuring DNS with NetworkManager #

For systems using NetworkManager, you can configure DNS settings using the nmcli tool:

nmcli con modify "Connection Name" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con up "Connection Name"

To see current DNS settings managed by NetworkManager:

nmcli dev show | grep DNS

5. Testing DNS Configuration #

Using dig:

dig @8.8.8.8 www.google.com

Using nslookup:

nslookup www.google.com 8.8.8.8

These commands test DNS resolution explicitly using the server 8.8.8.8.

Conclusion #

Properly configuring DNS on a Linux client helps ensure that network operations involving domain name resolution function efficiently and reliably. By mastering tools like resolvconf, nmcli, and systemd-resolve, and understanding the configuration files involved, you can effectively manage DNS settings in various Linux environments. Remember to test your configuration to ensure that DNS resolution is working as expected.