Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


CompTIA Linux+ XK0-005 - 1.5 - Name Resolution: systemd

Name resolution plays a vital role in network communication by translating human-readable domain names into IP addresses. Linux provides various tools and configuration options to manage name resolution. In this guide, we will explore two important tools: hostnamectl and resolvectl. These tools are part of the systemd suite, which is commonly used in modern Linux distributions.

hostnamectl

The hostnamectl command in Linux is a powerful tool that allows you to manage the hostname of your system. The hostname is a label assigned to a network node, typically used to identify and differentiate devices in a network. With hostnamectl, you can view, set, and modify the hostname of your Linux system. In this guide, we will explore various hostnamectl commands and their usage.

Checking the Current Hostname

To check the current hostname of your system, use the following command:

hostnamectl

Example output:

   Static hostname: mycomputer
   Transient hostname: -
   Operating System: Ubuntu 20.04.1 LTS
   Kernel: Linux 5.4.0-52-generic
   Architecture: x86_64

The output provides information about the current static hostname, transient hostname, operating system, kernel version, and architecture.

Setting the Hostname

To set a new hostname for your system, use the set-hostname option followed by the desired hostname. Ensure you have administrative privileges (such as using sudo) to modify system settings. For example:

sudo hostnamectl set-hostname mynewhostname

After setting the new hostname, you may need to restart the system or log out and log back in for the changes to take effect.

Displaying Only the Static Hostname

If you want to display only the static hostname without additional information, you can use the --static option. For example:

hostnamectl --static

Example output:

myhostname

This command specifically retrieves and displays the static hostname value.

The hostnamectl command is a useful utility for managing the hostname of your Linux system. Whether you need to check the current hostname, set a new hostname, or display the static hostname, hostnamectl provides the necessary functionality. By utilizing hostnamectl, you can easily configure and manage the hostname settings to suit your needs.

resolvectl

The resolvectl command in Linux allows you to manage DNS (Domain Name System) resolution settings on your system. DNS resolution is responsible for translating domain names to IP addresses, enabling communication between devices on a network. With resolvectl, you can view and modify the DNS configuration to ensure proper name resolution. In this guide, we will explore various resolvectl commands and their usage.

Checking DNS Configuration

To check the current DNS configuration on your system, use the following command:

resolvectl status

Example output:

Global
       LLMNR setting: yes
MulticastDNS setting: yes
  DNSOverTLS setting: no
      DNSSEC setting: allow-downgrade
    DNSSEC supported: yes
  Current DNS Server: 8.8.8.8
         DNS Servers: 8.8.8.8
                      8.8.4.4
          DNS Domain: example.net
                      example.home.arpa
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      ...
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (enp0s3)
      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: allow-downgrade
    DNSSEC supported: yes
  Current DNS Server: 8.8.8.8
         DNS Servers: 8.8.8.8
                      8.8.4.4
          DNS Domain: example.net

The output provides information about the enabled protocols and the DNS security status.

Displaying DNS Servers

To view the DNS servers configured on your system, use the following command:

resolvectl dns

Example output:

Link 2 (eth0)
       Current Scopes: DNS
        DNS Servers: 8.8.8.8
                     8.8.4.4

The output displays the DNS servers associated with the specified network link, such as eth0. Multiple DNS servers can be listed if configured.

Adding DNS Servers

To add DNS servers to your system configuration, you can use the resolvectl command with the dns option followed by the network interface and the IP addresses of the DNS servers. For example, to add DNS server 192.168.1.2 to the eth0 interface, use the following command:

sudo resolvectl dns eth0 192.168.1.2 8.8.4.4

After adding the DNS servers, they will be used for DNS resolution on the specified network interface.

The resolvectl command provides a convenient way to manage DNS resolution settings on your Linux system. Whether you need to check the current DNS configuration, view the configured DNS servers, or add new DNS servers, resolvectl offers the necessary functionality. By utilizing resolvectl, you can ensure proper DNS resolution and troubleshoot DNS-related issues effectively.

Conclusion

Proper name resolution is essential for network communication in Linux. In this guide, we explored two important tools, hostnamectl and resolvectl, which are part of the systemd suite. With hostnamectl, you can view and modify the system's hostname, while resolvectl allows you to manage DNS resolver configuration. These tools empower you to ensure accurate and efficient name resolution on your Linux system.

By mastering the usage of hostnamectl and resolvectl, you will have the knowledge and skills to manage the hostname and DNS settings, troubleshoot name resolution issues, and optimize network communication in your Linux environment. Remember to consult the respective command's manual pages (man) for more detailed information and additional options.


Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.