The hostname command displays or temporarily modifies the system's fully qualified hostname.
[root@host ~]# hostname
host.example.comSpecify a static hostname in the /etc/hostname file.
Use the hostnamectl command to modify this file, and view the system's fully qualified hostname.
If this file does not exist, then the hostname is set by a reverse DNS query when an IP address is assigned to the interface.
[root@host ~]#hostnamectl hostname host.example.com[root@host ~]#hostnamectl statusStatic hostname: host.example.com Icon name: computer-vm Chassis: vm 🖴 Machine ID: ace63d6701c2489ab9c0960c0f1afe1d Boot ID: 0edf5ba1830c48adbd6babfa08f0b867 Virtualization: kvm Operating System: Red Hat Enterprise Linux 9.0 (Plow) CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos Kernel: Linux 5.14.0-70.13.1.el9_0.x86_64 Architecture: x86-64 Hardware Vendor: Red Hat Hardware Model: OpenStack Compute [root@host ~]#cat /etc/hostnamehost.example.com
In Red Hat Enterprise Linux 7 and later versions, the static hostname is stored in the /etc/hostname file.
Red Hat Enterprise Linux 6 and earlier versions store the hostname as a variable in the /etc/sysconfig/network file.
The stub resolver converts hostnames to IP addresses or the reverse.
It determines where to look based on the configuration of the /etc/nsswitch.conf file.
By default, it attempts to resolve the query by first using the /etc/hosts file.
[root@host ~]# cat /etc/hosts
127.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.comThe getent hosts command tests hostname resolution with the hostname/etc/hosts file.
If an entry is not found in the /etc/hosts file, then the stub resolver uses a DNS name server to look up the hostname.
The /etc/resolv.conf file controls how this query is performed:
search
: A list of domain names to try with a short hostname. Either search or domain should be set in the same file; if they are both set, then only the last entry takes effect. See resolv.conf(5) for details.
nameserver
: The IP address of a name server to query. Up to three name server directives can be given to provide backups if one name server is down.
[root@host ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain example.com
search example.com
nameserver 172.25.254.254NetworkManager uses DNS settings in the connection configuration files to update the /etc/resolv.conf file.
Use the nmcli command to modify the connections.
[root@host ~]#nmcli con mod[root@host ~]#IDipv4.dnsIPnmcli con down[root@host ~]#IDnmcli con up[root@host ~]#IDcat /etc/NetworkManager/system-connections/...output omitted... [ipv4] ...output omitted... dns=8.8.8.8; ...output omitted...ID
The default behavior of the nmcli con mod ID ipv4.dns IP command is to replace any previous DNS settings with the new IP list that is provided.
A plus (+) or minus (-) character in front of the nmcli command ipv4.dns option adds or removes an individual entry, respectively.
[root@host ~]# nmcli con mod ID +ipv4.dns IPIn the following example, add the DNS server with an IPv6 IP address of 2001:4860:4860::8888 to the list of name servers on the static-ens3 connection.
[root@host ~]# nmcli con mod static-ens3 +ipv6.dns 2001:4860:4860::8888Static IPv4 and IPv6 DNS settings become nameserver directives in /etc/resolv.conf.
On a dual-stack system, keep listed at least one IPv4-reachable and an IPv6 name server (assuming a dual-stack system), in the event of networking issues with either stack.
The host command can test DNS server connectivity.HOSTNAME
[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 when interfaces are started, unless you specify ignore-auto-dns = yes in the relevant interface configuration file in the /etc/NetworkManager/system-connections/ directory.
Set this entry by using the nmcli command.
[root@host ~]# nmcli con mod "static-ens3" ipv4.ignore-auto-dns yesUse the dig command to test DNS server connectivity.HOSTNAME
[root@host ~]#dig classroom.example.com; <<>> DiG 9.16.23-RH <<>> classroom.example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3451 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 13, ADDITIONAL: 27 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ; COOKIE: 947ea2a936353423c3bc0d5f627cc1ae7147460e10d2777c (good) ;; QUESTION SECTION: ;classroom.example.com. IN A ;; ANSWER SECTION:classroom.example.com.85326 IN A172.25.254.254...output omitted...
Neither the host nor the dig commands view the configuration in the /etc/hosts file.
To test the /etc/hosts file, use the getent hosts command.HOSTNAME
[root@host ~]# getent hosts classroom.example.com
172.25.254.254 classroom.example.com
nmcli(1), hostnamectl(1), hosts(5), getent(1), host(1), dig(1), getent(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/9/html-single/configuring_and_managing_networking/index