Display and change system host name and name resolution configuration.
After completing this section, students should be able to configure and test system host name and name resolution.
The hostname command displays or temporarily modifies the system's fully qualified host name.
[root@desktopX ~]#hostnamedesktopX.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@desktopX ~]#hostnamectl set-hostname desktopX.example.com[root@desktopX ~]#hostnamectl statusStatic hostname: desktopX.example.com Icon name: computer Chassis: n/a Machine ID: 9f6fb63045a845d79e5e870b914c61c9 Boot ID: aa6c3259825e4b8c92bd0f601089ddf7 Virtualization: kvm Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo) CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server Kernel: Linux 3.10.0-97.el7.x86_64 Architecture: x86_64[root@desktopX ~]#cat /etc/hostnamedesktopX.example.com
The static host name is stored in /etc/hostname. Previous versions of Red Hat Enterprise Linux stored 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. The contents of the file /etc/hosts are checked first.
[root@desktopX ~]#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 with the /etc/hosts file.
If an entry is not found in that file, the stub resolver looks for the information from
a DNS nameserver. The /etc/resolv.conf file controls how this query is done:
nameserver: the IP address of a nameserver to query. Up to three
nameserver directives may be given to provide backups if one is down.
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.
[root@desktopX ~]#cat /etc/resolv.conf# Generated by NetworkManager domain example.com search example.com nameserver 172.25.254.254
NetworkManager will update the /etc/resolv.conf file using DNS settings in the connection configuration files. Use the
nmcli to modify the connections.
[root@desktopX ~]#nmcli con modIDipv4.dnsIP[root@desktopX ~]#nmcli con downID[root@desktopX ~]#nmcli con upID[root@desktopX ~]#cat /etc/sysconfig/network-scripts/ifcfg-... DNS1=8.8.8.8 ...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 +/- symbol in front of the ipv4.dns argument will add or remove an individual entry.
[root@desktopX ~]#nmcli con modID+ipv4.dnsIP
The host HOSTNAME command can be used to test DNS server connectivity.
[root@desktopX ~]#host classroom.example.comclassroom.example.com has address 172.25.254.254[root@desktopX ~]#host 172.25.254.254254.254.25.172.in-addr.arpa domain name pointer classroom.example.com.
If DHCP is in use, /etc/resolv.conf is automatically
rewritten as interfaces are started, unless you specify PEERDNS=no
in the relevant interface configuration files. The change can be made with nmcli.
[root@desktopX ~]#nmcli con mod "System eth0" ipv4.ignore-auto-dns yes
nmcli(1), hostnamectl(1), hosts(5), getent(1), host(1), and resolv.conf(5) man pages
Additional information may be available in the chapter on configuring host names in the Red Hat Enterprise Linux Networking Guide for Red Hat Enterprise Linux 7, which can be found at https://access.redhat.com/documentation/