how to configure DNS server settings in Linux 2025
This refinement specifies 'configure' and 'settings' for clarity, includes the context of DNS server settings, and adds the year for relevance to current methods and practices.
Configuring a DNS server in Linux is an essential skill for system administrators and users who want to customize their network settings. Different distributions may have varying methods for setting DNS servers, but the following guide outlines general approaches using command line interfaces and configuration files.
DNS (Domain Name System) helps translate human-readable domain names into IP addresses. Setting a DNS server can improve internet speed, enhance security, or allow the use of specific DNS services. Below, I’ll cover how to set DNS servers across various Linux distributions, specifically focusing on file editing methods and command line tools.
/etc/resolv.confFor many Linux distributions, DNS settings are managed through the /etc/resolv.conf file. This file stores the DNS servers the system uses for name resolution.
/etc/resolv.confnano or vim) to open the file:
sudo nano /etc/resolv.conf
nameserver 8.8.8.8 # Google DNS
nameserver 1.1.1.1 # Cloudflare DNS
CTRL + X, then Y, and hit Enter).It's important to note that some distributions may automatically overwrite this file. Thus, manual entries might not persist after a reboot or a network restart.
To ensure your DNS settings remain persistent across reboots, you may need to edit other configuration files depending on your Linux distribution.
In modern versions of Debian and Ubuntu (especially those using systemd), you should use the following:
nmcli dev show | grep DNS
nmcli con mod <connection-name> ipv4.dns "8.8.8.8,1.1.1.1"
nmcli con up <connection-name>
For Red Hat-based distributions, configure /etc/sysconfig/network-scripts/ifcfg-<interface>:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=8.8.8.8
DNS2=1.1.1.1
sudo systemctl restart network
systemd-resolvedFor systems using systemd, you might find that systemd-resolved manages DNS settings:
systemd-resolved is active:
systemctl status systemd-resolved
/etc/systemd/resolved.conf:
sudo nano /etc/systemd/resolved.conf
[Resolve] section:
[Resolve]
DNS=8.8.8.8 1.1.1.1
FallbackDNS=9.9.9.9
To apply changes, restart the service:
sudo systemctl restart systemd-resolved
Setting the DNS server in Linux can vary based on the distribution and network management tools used. While you can edit /etc/resolv.conf for quick changes, persistent configurations should be made within network manager settings or to specific network configuration files.
By understanding these steps, you can ensure better control over how your Linux system resolves domain names. For users looking to enhance security or performance, utilizing public DNS services like Google or Cloudflare can substantially improve browsing experiences. If you encounter any issues with your configuration, please consult your specific distribution’s documentation or community forums for additional support.