Linux domainname Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux domainname command, which is used to display or set the domain name of the system. The lab will cover understanding the domainname command, setting and displaying the domain name, and managing the domain name across network interfaces. We will provide practical examples to demonstrate the usage of this command and highlight important considerations when working with domain names in a Linux environment.

The domainname command is a useful tool for managing the domain name of a system, which is a unique identifier for a network or a group of computers. In this lab, we will learn how to check the current domain name, set a new domain name, and ensure that the domain name is persistent across reboots. Additionally, we will discuss how to manage the domain name across different network interfaces, which can be particularly useful in scenarios where a system is connected to multiple networks.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("`IP Managing`") linux/SystemInformationandMonitoringGroup -.-> linux/hostname("`Hostname Managing`") subgraph Lab Skills linux/echo -.-> lab-422647{{"`Linux domainname Command with Practical Examples`"}} linux/sudo -.-> lab-422647{{"`Linux domainname Command with Practical Examples`"}} linux/ip -.-> lab-422647{{"`Linux domainname Command with Practical Examples`"}} linux/hostname -.-> lab-422647{{"`Linux domainname Command with Practical Examples`"}} end

Understand the domainname Command

In this step, we will explore the Linux domainname command, which is used to display or set the domain name of the system. The domain name is a unique identifier for a network or a group of computers that are connected to the same network.

First, let's check the current domain name of the system using the domainname command:

domainname

Example output:

(none)

As you can see, the domain name is currently set to (none), which means that no domain name has been configured for this system.

The domainname command can also be used to set the domain name. To do this, we can use the following syntax:

sudo domainname example.com

This will set the domain name of the system to example.com. You can verify the new domain name by running the domainname command again:

domainname

Example output:

example.com

Now, the domain name of the system is set to example.com.

It's important to note that the domain name set using the domainname command is only valid for the current session. To make the domain name persistent across reboots, you would need to modify the system's network configuration files.

Set and Display the Domain Name

In this step, we will learn how to set and display the domain name of the system using the domainname command.

First, let's check the current domain name of the system:

domainname

Example output:

example.com

As you can see, the domain name is currently set to example.com.

Now, let's change the domain name to mycompany.com:

sudo domainname mycompany.com

To verify the new domain name, run the domainname command again:

domainname

Example output:

mycompany.com

The domain name has been successfully changed to mycompany.com.

It's important to note that the domain name set using the domainname command is only valid for the current session. To make the domain name persistent across reboots, you would need to modify the system's network configuration files.

Manage Domain Name Across Network Interfaces

In this step, we will learn how to manage the domain name across multiple network interfaces on the system.

First, let's check the current domain name:

domainname

Example output:

mycompany.com

Now, let's create a new network interface and set a different domain name for it:

sudo ip link add dummy0 type dummy
sudo ip link set dummy0 up
sudo domainname -d example.net

Here, we created a new dummy network interface named dummy0 and set the domain name for this interface to example.net.

To verify the domain name for the new interface, run the domainname command again:

domainname

Example output:

example.net

As you can see, the domain name has been changed to example.net.

To revert the domain name back to the original setting, you can use the following command:

sudo domainname -F /etc/hostname

This will reset the domain name to the value specified in the /etc/hostname file.

Let's verify the domain name again:

domainname

Example output:

mycompany.com

The domain name has been reverted to mycompany.com.

This demonstrates how you can manage the domain name across different network interfaces on your system.

Summary

In this lab, you learned how to use the Linux domainname command to display and set the domain name of the system. You explored the basic usage of the command, including checking the current domain name and changing it to a new value. You also learned that the domain name set using the domainname command is only valid for the current session, and to make it persistent, you would need to modify the system's network configuration files.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like