After completing this section, you should be able to configure a server’s static host name and its name resolution and test the results.
The hostname command displays or temporarily modifies the system's fully qualified host name.
[root@host ~]#hostnamehost.example.com
A static host name may be specified in the /etc/hostname file.
The hostnamectl command is used to modify this file and may be used to view the status of the system's fully qualified host name.
If this file does not exist, the host name is set by a reverse DNS query once the interface has an IP address assigned.
[root@host ~]#hostnamectl set-hostname host.example.com[root@host ~]#hostnamectl statusStatic hostname: host.example.com Icon name: computer-vm Chassis: vm Machine ID: f874df04639f474cb0a9881041f4f7d4 Boot ID: 6a0abe03ef0b4a97bcb8afb7b281e4d3 Virtualization: kvm Operating System: Red Hat Enterprise Linux 8.2 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.2:GA Kernel: Linux 4.18.0-193.el8.x86_64 Architecture: x86-64[root@host ~]#cat /etc/hostnamehost.example.com
In Red Hat Enterprise Linux 7 and later, the static host name is stored in /etc/hostname.
Red Hat Enterprise Linux 6 and earlier stores the host name as a variable in the /etc/sysconfig/network file.
The stub resolver is used to convert host names to IP addresses or the reverse.
It determines where to look based on the configuration of the /etc/nsswitch.conf file.
By default, the contents of the /etc/hosts file are checked first.
[root@host ~]#cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.25.254.254 classroom.example.com 172.25.254.254 content.example.com
The getent hosts hostname command can be used to test host name resolution using the /etc/hosts file.
If an entry is not found in the /etc/hosts file, by default the stub resolver tries to look up the hostname by using a DNS nameserver.
The /etc/resolv.conf file controls how this query is performed:
search: a list of domain names to try with a short host name.
Both this and domain should not be set in the same file; if they are, the last instance wins.
See resolv.conf(5) for details.
nameserver: the IP address of a nameserver to query.
Up to three nameserver directives may be given to provide backups if one is down.
[root@host ~]#cat /etc/resolv.conf# Generated by NetworkManager domain example.com search example.com nameserver 172.25.254.254
NetworkManager updates the /etc/resolv.conf file using DNS settings in the connection configuration files.
Use the nmcli command to modify the connections.
[root@host ~]#nmcli con modIDipv4.dnsIP[root@host ~]#nmcli con downID[root@host ~]#nmcli con upID[root@host ~]#cat /etc/sysconfig/network-scripts/ifcfg-...output omitted... DNS1=8.8.8.8 ...output omitted...ID
The default behavior of nmcli con mod ID ipv4.dns IP is to replace any previous DNS settings with the new IP list provided.
A + or - symbol in front of the ipv4.dns argument adds or removes an individual entry.
[root@host ~]#nmcli con modID+ipv4.dnsIP
To add the DNS server with IPv6 IP address 2001:4860:4860::8888 to the list of nameservers to use with the connection static-ens3:
[root@host ~]#nmcli con mod static-ens3 +ipv6.dns 2001:4860:4860::8888
Static IPv4 and IPv6 DNS settings all end up as nameserver directives in /etc/resolv.conf.
You should ensure that there is, at minimum, an IPv4-reachable name server listed (assuming a dual-stack system).
It is better to have at least one name server using IPv4 and a second using IPv6 in case you have network issues with either your IPv4 or IPv6 networking.
Testing DNS Name Resolution
The host HOSTNAME command can be used to test DNS server connectivity.
[root@host ~]#host classroom.example.comclassroom.example.com has address 172.25.254.254[root@host ~]#host 172.25.254.254254.254.25.172.in-addr.arpa domain name pointer classroom.example.com.
DHCP automatically rewrites the /etc/resolv.conf file as interfaces are started unless you specify PEERDNS=no in the relevant interface configuration files.
Set this using the nmcli command.
[root@host ~]#nmcli con mod "static-ens3" ipv4.ignore-auto-dns yes
nmcli(1),
hostnamectl(1),
hosts(5),
getent(1),
host(1),
and resolv.conf(5) man pages
For more information, refer to the Configuring and Managing Networking Guide at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_networking/