Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Configure DNS Settings in Linux Using resolv.conf

The /etc/resolv.conf file in Linux is a critical configuration file that specifies the DNS servers your system uses to resolve domain names into IP addresses. Understanding how to configure and manage this file is essential for network troubleshooting and ensuring your system can communicate effectively over the internet.

Understanding resolv.conf

The resolv.conf file typically contains lines specifying the DNS servers and search domains. The basic structure of the file includes:

  • nameserver: Specifies the IP address of a DNS server. You can list multiple DNS servers by adding multiple nameserver lines.
  • search: Specifies the search domains. When you enter a hostname without a domain, the system will append each of the search domains in turn to try to resolve the hostname.

Example of a resolv.conf File

Here is a simple example of what a typical resolv.conf file might look like:

nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com

In this example, Google's public DNS servers (8.8.8.8 and 8.8.4.4) are used, and example.com is the search domain.

How to Edit resolv.conf

  1. Open the File: Use a text editor like nano or vi to open the file. You may need superuser privileges to edit it.

    sudo nano /etc/resolv.conf
  2. Modify the File: Add or change the nameserver and search entries as needed.

  3. Save the Changes: Save the file and exit the editor.

Persisting Changes

On many modern Linux systems, network management services like NetworkManager or systemd-resolved can overwrite resolv.conf. To make persistent changes, you might need to:

  • NetworkManager: Edit the configuration files in /etc/NetworkManager/ or use nmcli to set DNS servers.

    nmcli con mod <connection_name> ipv4.dns "8.8.8.8 8.8.4.4"
    nmcli con up <connection_name>
  • systemd-resolved: Use resolvectl or edit /etc/systemd/resolved.conf.

    sudo resolvectl dns eth0 8.8.8.8 8.8.4.4

Testing DNS Configuration

After editing resolv.conf, you can test your DNS configuration with tools like dig or nslookup:

dig example.com

or

nslookup example.com

These commands will show you which DNS server is being queried and the response it provides.

Conclusion

The resolv.conf file is a foundational component of DNS configuration in Linux. By understanding how to edit and manage this file, you can ensure that your system resolves domain names correctly and efficiently. Always remember to consider the impact of network management services that might overwrite your changes and use the appropriate tools to make persistent modifications.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.