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:
/etc/hostsfile β Local static mapping.- DNS (Domain Name System) β Centralized server-based mapping.
nsswitch.confconfiguration β 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/hostsfirst (depending onnsswitch.conforder). - 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
pingchecks connectivity.getent hostsqueries 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
nmcliconfigurations
/etc/resolv.conffile format: nameserver 192.168.1.1
search example.localnameserverβ 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
nslookupanddigquery 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:
- Check
/etc/hostsfirst (files) - Then query DNS (
dns)
- Check
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:
- Ping a hostname
ping webserver.local
- Query host info
getent hosts webserver.local
- Check DNS info
nslookup webserver.local
dig webserver.local
4. Key Files and Commands Summary
| Task | File / Command | Purpose |
|---|---|---|
| Local hostname mapping | /etc/hosts | Map hostname β IP |
| DNS server info | /etc/resolv.conf | Set DNS IP & search domain |
| Hostname resolution order | /etc/nsswitch.conf | Control order (files, DNS, etc.) |
| View hostname | hostname, hostnamectl status | See current hostname |
| Set hostname | hostnamectl set-hostname <name> | Configure hostname |
| Test resolution | ping, getent hosts, nslookup, dig | Verify mapping works |
5. Exam Tips for RHCSA
- Always check
/etc/hostsfirst for manual mapping. - Use
hostnamectlto set or change system hostname. - Verify DNS resolution using
getent hostsornslookup. - Know how nsswitch.conf controls the lookup order.
- 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, ordig.
