in linux, how to set the dns server

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.

Understanding DNS Configuration

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.


1. Configuration Using /etc/resolv.conf

For 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.

Steps to Edit /etc/resolv.conf

  1. Open the Terminal.
  2. Use a text editor (like nano or vim) to open the file:
    sudo nano /etc/resolv.conf
    
  3. Add the DNS server addresses using the format:
    nameserver 8.8.8.8  # Google DNS
    nameserver 1.1.1.1  # Cloudflare DNS
    
  4. Save and exit the editor (in Nano, press 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.


2. Persistent DNS Configuration

To ensure your DNS settings remain persistent across reboots, you may need to edit other configuration files depending on your Linux distribution.

Debian/Ubuntu:

In modern versions of Debian and Ubuntu (especially those using systemd), you should use the following:

  1. Modify NetworkManager settings via graphical interface (if available) or via command line:
    nmcli dev show | grep DNS
    
  2. To set DNS for a specific connection:
    nmcli con mod <connection-name> ipv4.dns "8.8.8.8,1.1.1.1"
    nmcli con up <connection-name>
    

Red Hat/CentOS:

For Red Hat-based distributions, configure /etc/sysconfig/network-scripts/ifcfg-<interface>:

  1. Open the respective configuration file:
    sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
    
  2. Add or modify the following line:
    DNS1=8.8.8.8
    DNS2=1.1.1.1
    
  3. Restart the network service:
    sudo systemctl restart network
    

3. Using systemd-resolved

For systems using systemd, you might find that systemd-resolved manages DNS settings:

  1. Check if systemd-resolved is active:
    systemctl status systemd-resolved
    
  2. Open or create /etc/systemd/resolved.conf:
    sudo nano /etc/systemd/resolved.conf
    
  3. Set the DNS servers in the [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

Conclusion

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.

Sources

10
1
Linux DNS Server Configuration: Detailed Guide [2025]
Mailserverguru

Step #1: Update the System; Step #2: Install DNS Server Packages; Step #3: Explain named.conf File; Step #4: Configure DNS Server Options; Step ...See more

2
How to use the Linux BIND command to install and ...
Redhat

Configure the /etc/named.conf file. First, add or edit the two values in the options field. One is the DNS server address, and the other is the ...See more

3
Step-by-Step Guide on How to Change Linux DNS
1gbits

Update DNS Settings. Select your connection, go to the "IPv4 Settings" tab, and enter your preferred DNS server addresses. Save and Reconnect.See more

4
How to set DNS from command line on Ubuntu 20.04 ...
Askubuntu

This is a dynamic resolv.conf file for connecting local clients directly to all known uplink DNS servers. This file lists all configured search domains.See more

5
How can I configure my DNS settings on Debian 12?
Serverfault

I'm trying to change my DNS settings on my Debian 12 VPS, and by this I mean, I want to use a public resolver like 1.1.1.1 instead of my VPS host's resolver.See more

6
How to Configure a DNS Server: Step-by-Step Guide
Ninjaone

Follow the prompts to install the DNS server role. After installation, open “DNS Manager” to configure DNS settings. Create DNS zones, add ...See more

7
How to setup DNS manually on Linux?
Unix

1. Resolvconf: Config files cat /etc/resolvconf/resolv. · 2. Dnsmasq Service: Config files cat /etc/dnsmasq. · 3. Network Manager: Config files / ...See more

8
Question on manually setting my DNS server address
Linux

In my typical setup I have the IP address automatic and I manually set the DNS to 1.1.1.1 subnet 1.0.0.1. Now also in that user interface, the ...See more

9
Change DNS after many upgrades (24.04.1 LTS)
Discourse

I recently notice my server is using the wrong DNS and no longer obeyed my setting. And I guess this is due many upgrades as I still use the /etc/network/ ...See more

10
How to Configure DNS on Linux
Geeksforgeeks

Open Linux Terminal · Install BIND · Opne BIND Config File · Add Smaple Address · Add Forward & Reverse Lookup in Linux · Update Serial Number.See more