Master dnsdomainname in Ubuntu: Inspect FQDN and Domains

Overview

In enterprise Linux administration, verifying an endpoint’s fully qualified domain name (FQDN) alongside its associated DNS domain suffix forms the cornerstone of dependable networking and service discovery. This walkthrough breaks down how the dnsdomainname utility resolves domain metadata, demonstrates step-by-step domain configuration, and clarifies how to interpret terminal output under different operational contexts.

Provisioning Tools and Basic Command Mechanics

Before exploring domain resolution mechanics, ensure your environment has the core host and DNS diagnostics utilities available by running apt-get update -qq && apt-get install -y hostname bind9-dnsutils.

Installing hostname and DNS diagnostic utilities

Querying the system’s simple, unadorned node identifier is handled by invoking hostname.
The shell immediately prints the active short hostname assigned to the current operating instance.

Checking basic system hostname

To discover whether the operating environment resolves into a complete fully qualified domain name, execute hostname -f.
Whenever a node operates without an explicit domain hierarchy mapped to its records, the terminal falls back to rendering the bare host label alone.

Querying the fully qualified domain name

The dnsdomainname command isolates and displays only the DNS domain portion of the host’s FQDN, stripping away the individual machine prefix.
If no DNS suffix or search domain is attached to the system identity, the command returns nothing and exits silently.
⚙️ [Core Diagnostic Flags]

-v (--verbose) : Produces debugging output tracking domain resolution logic.
-A (--all-fqdns) : Enumerates each FQDN bound across all provisioned network interfaces.
-d (--domain) : Returns the system’s DNS domain component (mirrors default dnsdomainname behavior).
-f (--fqdn, --long) : Prints the full canonical FQDN registered to the machine.
-i (--ip-address) : Resolves and outputs the network IP addresses bound to the host identifier.

Evaluating raw dnsdomainname output

Crafting Local Domain Mappings via /etc/hosts

To safeguard your pristine networking settings against accidental misconfiguration, generate an archival duplicate using cp /etc/hosts /etc/hosts.bak.

Backing up /etc/hosts configuration

You can construct a reproducible local domain sandbox by piping a custom static record into your hosts file with echo '127.0.1.1 webserver.example.local webserver' >> /etc/hosts.

Injecting synthetic loopback record into /etc/hosts

Now update the kernel’s active runtime hostname to match the new record by executing hostname webserver.

Updating runtime hostname to webserver

Rerunning hostname -f leverages the fresh static lookups inside /etc/hosts to assemble the system’s canonical address.
The shell faithfully returns the fully qualified identifier webserver.example.local.

Verifying updated FQDN resolution

When invoked against this setup, dnsdomainname cleanly separates the system hierarchy and isolates the root domain namespace.
The utility trims the leading webserver node prefix and renders example.local directly to stdout.

Extracting isolated domain via dnsdomainname

Cross-Checking with hostname and systemd hostnamectl

Executing hostname -d offers an alternate native technique to extract your DNS domain component.
As expected, it reflects identical resolution parameters by spitting out example.local.

Testing hostname domain flag lookup

On modern systemd-driven installations, running hostnamectl status delivers an all-inclusive snapshot encompassing static identifiers, chassis classification, and kernel architecture.
This output presents both persistent static labels and dynamic deployment properties at a glance.

Inspecting system identity with hostnamectl

To provision a formal systemd-tracked identifier complete with domain scoping, apply hostnamectl set-hostname node01.corp.internal.

Applying structured hostname via hostnamectl

Running dnsdomainname tests how local resolver policies prioritize name-to-address relationships.
Because /etc/hosts still anchors loopback address definitions to our prior entries, the resolver continues outputting example.local rather than the newly injected systemd string.

Observing resolver precedence with dnsdomainname

To audit all domains tied across local socket interfaces, execute hostname -A.
This parses reverse DNS mappings and reveals container or interface-specific host aliases established across the stack.

Enumerating interface-bound domain identities

Diagnostic Troubleshooting and State Restoration

A quick look inside the resolver configuration via cat /etc/resolv.conf reveals the active nameserver pointers and domain search scopes governing the OS.
Reviewing these directives ensures outward name lookups rely on intended nameserver routes.

Viewing resolver configuration in /etc/resolv.conf

When troubleshooting command behavior, running dnsdomainname -v may display argument syntax warnings depending on whether the underlying binary symlinks to specialized BSD or GNU coreutils variants.
Checking platform-specific parameter support prevents unexpected script failures when automating cross-distro infrastructure.

Handling verbose flag variation on symlinked utilities

With our lab scenarios completed, roll back the modified loopback mappings by restoring the original state with cp /etc/hosts.bak /etc/hosts.

Restoring /etc/hosts from backup archive

Reset the machine identifier back to a standard baseline node designation using hostnamectl set-hostname ubuntu-server.

Resetting default server hostname

Finally, verify that the environment has cleanly returned to its baseline state by running dnsdomainname.
With custom domain suffixes wiped from local resolver tables, the tool outputs an empty string, signifying a clean, unmapped default host state.

Confirming unmapped domain state post-cleanup

Mastering how dnsdomainname, /etc/hosts, and systemd resolution interplay gives you precise control over host naming and FQDN discovery. Incorporate these foundational checks into your provisioning workflows to eliminate tricky networking snags before they disrupt production services.