Overview
In enterprise Linux environments utilizing legacy directory services, the domainname utility plays an indispensable role in inspecting and defining NIS (Network Information Service) and YP (Yellow Pages) domain memberships. Many system administrators conflate NIS domains with Internet DNS domain names configured via hostname -d. This walkthrough breaks down their architectural distinctions and provides hands-on procedures for temporary session assignments as well as persistent configuration across machine reboots.
Installing the Required Utilities and Checking Current NIS Status
Before querying NIS properties on a clean Ubuntu installation, ensure that the core utilities supplied by the hostname package are installed on your host.

Executing domainname without arguments inspects the kernel for an active NIS/YP authentication domain. When the system returns (none), the host currently has no association with any NIS workgroup.
⚙️ [Notable Flags]
-v (--verbose): Outputs diagnostic runtime operations to standard output.-F (--file): Parses and applies the domain string directly from a specified text file.

The command ypdomainname serves as a dedicated symlink pointing to the same underlying utility. It verifies whether Yellow Pages database services have been bound to a specific domain context. An explicit error message alerts the administrator when this property remains unset.

Similarly, nisdomainname functions as an alias within the GNU/Linux toolchain. Running this command confirms the absence of an active NIS realm with a matching diagnostic alert.

Core Differences: domainname vs. hostname
System engineers must clearly separate network identification from directory authentication domains. The standard hostname utility queries the node’s local machine identifier within the network stack. Here, the operating system responds with its short node ID 76123fc60eb4.

Evaluating hostname -d requests the Domain Name System (DNS) search suffix designated for IP-based network resolution. If standard resolver configurations have not assigned an authoritative DNS zone, the command yields a blank line.

Appending the -f flag invokes a search for the Fully Qualified Domain Name (FQDN). In environments where no broader DNS domain has been bound, the kernel resolves the FQDN strictly to the bare local hostname.

In contrast, invoking domainname targets the distinct NIS/YP directory domain maintained separately inside the kernel’s network parameters. The output of (none) confirms that DNS resolution and NIS user authentication operate through completely decoupled subsystems.

Configuring and Clearing Runtime NIS Domains
System administrators can immediately assign a live NIS domain to the running kernel by executing domainname with elevated privileges. Running sudo domainname example-nis.local updates the active memory tables silently upon success.

A subsequent invocation of domainname confirms that the kernel network state reflects the newly designated domain string example-nis.local.

To flush or tear down this environment variable, pass an empty string argument ("") under root permissions. The command exits cleanly, purging the cached domain identifier from the kernel.

Re-evaluating the configuration verifies that the NIS domain attribute has reverted to its unconfigured, empty default state.

Persisting NIS Domain Settings Across Reboots
Runtime updates made directly via the command line do not survive an operating system reboot. To make a domain binding permanent on Debian and Ubuntu distributions, pipe the target domain string into /etc/defaultdomain using root permissions.

Inspect the target configuration file to ensure the string lab-nis.local was recorded accurately without trailing syntax anomalies.

Rather than rebooting the node to load the static file, apply the updated configuration immediately to the active session by feeding the file contents back into domainname.

Running domainname one final time validates that the live kernel has adopted the persistent value lab-nis.local.

Mastering the mechanics of the domainname toolchain ensures proper coexistence between network DNS resolvers and centralized directory authentication systems in Linux environments.