Configure hostname resolution

8. Manage Basic Networking

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


What is hostname resolution?
Hostname resolution is the process your Linux system uses to convert a human-readable hostname (like webserver.local) into an IP address (like 192.168.1.10) so that network communication can happen. Without hostname resolution, computers would have to use IP addresses only, which is hard to remember and manage.


1. Methods of Hostname Resolution

Red Hat systems use three main methods to resolve hostnames:

  1. /etc/hosts file – Local static mapping.
  2. DNS (Domain Name System) – Centralized server-based mapping.
  3. nsswitch.conf configuration – Determines the order of resolution methods.

1.1 /etc/hosts File

The /etc/hosts file is a simple text file where you can manually map hostnames to IP addresses.

  • Location: /etc/hosts
  • Format of each line: IP_address hostname [aliases…]
  • Example: 192.168.1.10 webserver.local webserver
    192.168.1.20 dbserver.local dbserver

How it works:

  • When your system tries to reach webserver.local, it checks /etc/hosts first (depending on nsswitch.conf order).
  • If it finds the IP there, it uses it. If not, it moves to the next method (DNS).

Exam Tip:
You should know how to add, edit, and remove entries in /etc/hosts.

Commands to verify:

ping webserver.local
getent hosts webserver.local
  • ping checks connectivity.
  • getent hosts queries the hosts database and shows what the system resolves.

1.2 DNS (Domain Name System)

DNS is the network-based method for resolving hostnames into IPs.

  • Red Hat Linux clients get DNS server information from:
    • /etc/resolv.conf
    • NetworkManager or nmcli configurations
  • /etc/resolv.conf file format: nameserver 192.168.1.1
    search example.local
    • nameserver – IP of the DNS server.
    • search – Domain to append to short hostnames.

Example:
If /etc/resolv.conf has:

nameserver 192.168.1.1
search example.local

and you ping webserver, the system tries webserver.example.local first.

Exam Tip:

  • You may need to verify DNS resolution using commands like:
ping webserver.local
nslookup webserver.local
dig webserver.local
  • nslookup and dig query the DNS server and show detailed info.

1.3 Name Service Switch (/etc/nsswitch.conf)

The /etc/nsswitch.conf file controls the order in which your system tries to resolve hostnames.

  • Relevant line:
hosts: files dns
  • This means:
    1. Check /etc/hosts first (files)
    2. Then query DNS (dns)

Exam Tip:
You should know how to check and modify the resolution order if needed.


2. Changing the System Hostname

A hostname is the name of the computer itself. Configuring hostname correctly is part of hostname resolution setup.

2.1 Viewing the Hostname

hostnamectl status
hostname

2.2 Setting a Temporary Hostname

hostnamectl set-hostname tempname
  • This changes the hostname until next reboot if not permanent.

2.3 Setting a Permanent Hostname

hostnamectl set-hostname permanentname
  • This updates system configuration files (/etc/hostname), and persists across reboots.

Exam Tip:
You may be asked to set both static and transient hostnames. RHCSA expects you to use hostnamectl.


3. Testing Hostname Resolution

After configuration, you should verify that your system can resolve hostnames correctly.

Commands:

  1. Ping a hostname
ping webserver.local
  1. Query host info
getent hosts webserver.local
  1. Check DNS info
nslookup webserver.local
dig webserver.local

4. Key Files and Commands Summary

TaskFile / CommandPurpose
Local hostname mapping/etc/hostsMap hostname β†’ IP
DNS server info/etc/resolv.confSet DNS IP & search domain
Hostname resolution order/etc/nsswitch.confControl order (files, DNS, etc.)
View hostnamehostname, hostnamectl statusSee current hostname
Set hostnamehostnamectl set-hostname <name>Configure hostname
Test resolutionping, getent hosts, nslookup, digVerify mapping works

5. Exam Tips for RHCSA

  1. Always check /etc/hosts first for manual mapping.
  2. Use hostnamectl to set or change system hostname.
  3. Verify DNS resolution using getent hosts or nslookup.
  4. Know how nsswitch.conf controls the lookup order.
  5. Always confirm your changes without reboot (using commands above).

βœ… Summary for Students:

  • Hostname resolution converts names β†’ IP addresses.
  • It can be local (/etc/hosts) or via DNS.
  • The order of lookup is controlled by /etc/nsswitch.conf.
  • You can view and set hostnames using hostnamectl.
  • Always test using ping, getent, nslookup, or dig.
Buy Me a Coffee