Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
RHCSA - Manage Basic Networking: Configure Hostname Resolution
Hostname resolution involves the process of translating human-readable hostnames into their corresponding IP addresses, enabling communication between devices on a network. This translation is facilitated by the Domain Name System (DNS), a distributed hierarchical system that maps hostnames to IP addresses.
Local Hostname Resolution Using /etc/hosts
The /etc/hosts
file is a text file used to manually map hostnames to IP addresses. It is a simple local DNS (Domain Name System) lookup mechanism that allows you to associate specific IP addresses with domain names, effectively bypassing the need to query a DNS server for address resolution. This file is consulted by the system before making DNS requests to resolve domain names to IP addresses.
Each line in the /etc/hosts
file represents an entry that associates an IP address with one or more hostnames. An example /etc/hosts
file is as follows, with each entry having an IP address, fully qualified domain name (FQDN) and aliases:
# Local Host
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# Local network printers
192.168.1.50 printer1.example.com printer1
192.168.1.51 printer2.example.com printer2
# File shares and servers
192.168.1.100 files.example.com files docs
192.168.1.101 storage.example.com storage archive
# SFTP server
192.168.1.200 sftp-server.example.com sftp-server sftp
When it comes to handling multiple entries for the same IP address, it's generally recommended to place the (FQDN) as the first entry after the IP address, followed by any aliases. This is important for certain network services and applications that rely on reverse DNS lookups to determine the canonical name associated with an IP address.
Add an entry to /etc/hosts
:
For this exercise, my IP is 192.168.0.219
, my FQDN is rhcsa-install.home.arpa
and my hostname is rhcsa-install
. Replace these with your equivalents in the exercises.
Attempt to ping your hostname:
ping -c 1 rhcsa-install
It should fail with:
ping: rhcsa-install: Name or service not known
Add an entry to /etc/hosts
:
echo '192.168.0.219 rhcsa-install.home.arpa rhcsa-install' | sudo tee -a /etc/hosts
Attempt to ping your hostname again:
ping -c 1 rhcsa-install
It should succeed with:
PING rhcsa-install.home.arpa (192.168.0.219) 56(84) bytes of data.
64 bytes from rhcsa-install.home.arpa (192.168.0.219): icmp_seq=1 ttl=64 time=0.032 ms
--- rhcsa-install.home.arpa ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.032/0.032/0.032/0.000 ms
Hostname Resolution Using DNS Servers
The /etc/resolv.conf
file contains information about the DNS resolver configuration, including the IP addresses of DNS servers that the system should query when it needs to resolve domain names. Each line in the file typically represents a directive or configuration option. The most common directive found in this file is the nameserver
directive, followed by the IP addresses of the DNS servers.
For example, a typical /etc/resolv.conf
file might look like this:
# Generated by NetworkManager
search example.com home.arpa
nameserver 8.8.8.8
nameserver 8.8.4.4
In this example, the system is configured to use Google's public DNS servers for domain name resolution.
Direct edits to /etc/resolv.conf
file may be overwritten by NetworkManager when network configurations change. Instead of editing the file directly, it's recommended to use NetworkManager's tools and configuration files to manage your network settings, which will ensure that updates are handled appropriately.
NetworkManager automatically updates the /etc/resolv.conf
file with the DNS server information provided by the network you are connected to. This ensures that your system uses the correct DNS servers for domain name resolution while adapting to changes in your network environment.
Here's a simplified overview of how NetworkManager updates the /etc/resolv.conf
file:
- NetworkManager detects changes in network connections, such as connecting to a new network or disconnecting from a network.
- When a network change is detected, NetworkManager obtains DNS server information from the network (usually provided by DHCP or other network configuration methods).
- NetworkManager then updates the
/etc/resolv.conf
file with the new DNS server addresses. - If the network connection changes again or the system is rebooted, NetworkManager will repeat this process to ensure the
/etc/resolv.conf
file remains accurate.
Configure the DNS servers used for a connection:
Determine the connection you wish to update the DNS servers in use for
nmcli con show
In my case, the enp0s3
connection will be used but change this to your connection for the remainder of the exercises:
NAME UUID TYPE DEVICE
enp0s3 29c942f7-9ff2-3e56-99b8-2edd84c50ada ethernet enp0s3
lo e746ac42-d492-46a5-aa91-59cfc1cfd7a0 loopback lo
Modify the connection to set Google's primary DNS server to be used for the enp0s3
connection
sudo nmcli con mod enp0s3 ipv4.dns 8.8.8.8
The command is broken down as follows:
con mod
: Modify a connectionenp0s3
: For connection name ofenp0s3
ipv4.dns "8.8.8.8"
: Setting DNS server to Google's Primary DNS
To activate the updated enp0s3
connection, run:
sudo nmcli con up enp0s3
You can use the nmcli
command to verify the the DNS settings have updated:
nmcli con show enp0s3 | grep 'ipv4.dns:'
ipv4.dns details should show as:
ipv4.dns: 8.8.8.8
You can see that the /etc/resolv.conf
file has also had the nameserver entries updated:
If your connection is set to method=auto
(using DHCP), you will also see the nameserver entries that DHCP configures as is the case in this example:
cat /etc/resolv.conf
# Generated by NetworkManager
search example.com home.arpa
nameserver 8.8.8.8
nameserver 187.212.5.50
nameserver 187.212.10.100
If you want to add another DNS server, in this case, Google's Secondary DNS server, you use the +
symbol in front of ipv4.dns
:
sudo nmcli con mod enp0s3 +ipv4.dns 8.8.4.4
To activate the updated enp0s3
connection, run:
sudo nmcli con up enp0s3
You can use the nmcli
command to verify the the DNS settings have updated:
nmcli con show enp0s3 | grep 'ipv4.dns:'
ipv4.dns details should show as:
ipv4.dns: 8.8.8.8,8.8.4.4
You can see that the /etc/resolv.conf
file has also had the nameserver entries updated:
cat /etc/resolv.conf
# Generated by NetworkManager
search cable.virginm.net home.arpa
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 194.168.4.100
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 194.168.8.100
Notice that it mentions the resolver may not support more than 3 nameservers. This is not a problem in our scenario as the manually specified entries come before DHCP.
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.