Defining Host name and Host name resolution

Identifying Hosts on the Network

  • Definition of Host Name: A host name is a label assigned to a device connected to a computer network that is used to identify the device in various forms of electronic communication.

  • Setting Host Name During Installation:

    • You can set the host name while installing your server.

    • If you forget to specify a host name during installation, you can use the command hostnamectl set-hostname <new-hostname> later to manage host names.

    • The host name is written to the file /etc/hostname.

  • Resolving Host Names:

    • To resolve host names, the system uses the file /etc/hosts.

    • In the /etc/hosts file, entries are formatted as:

    • IP_address hostname, for example, 100.0.0.11 server2.example.com servertwo.

Using DNS in the Real World

  • Domain Name System (DNS):

    • A more convenient solution for name resolution over the local /etc/hosts file is utilizing DNS.

    • You can configure the DNS client through the file /etc/resolv.conf.

    • This file contains the IP address of the DNS server, which allows you to find all hosts on the Internet by name.

    • The theoretical order of host name resolution can be influenced through the configuration in /etc/nsswitch.conf.

    • You can prioritize the order of resolution between local host name resolution and DNS queries.

Practical Demonstration and Configuration

  • Demo Context:

    • Conducting a demonstration from another host that was installed without specifying a host name.

    • The output of the hostname command shows localhost.localdomain.

  • Setting the Host Name Using Command Line:

    • Using the command hostnamectl set-hostname rh2.example.com to specify a new host name.

    • The change may not be immediately recognized in the current shell; a new shell session needs to be opened to see the updated host name (e.g., RHCCSSA2).

Updating /etc/hosts for Host Name Resolution

  • Inspecting /etc/hosts:

    • When checking the /etc/hosts file, you may still see entries for localhost.localdomain.

    • To ensure proper function, you need to add rhcsa2.example.com and the short name rhcsa2 to the file for the system to resolve host names correctly.

    • For IPv6 addresses, similar entries need to be added by following the same format.

  • Ping Testing:

    • After updates, using the ping command to check connectivity shows results from the IP ::1 (IPv6 address).

    • This confirms the IPv6 stack is functioning properly, even if IPv4 is preferred!

Configuring /etc/resolv.conf and /etc/nsswitch.conf

  • Contents of /etc/resolv.conf:

    • The /etc/resolv.conf file specifies DNS nameserver settings.

    • Example: nameserver 192.168.29.2 is a name server automatically assigned by the DHCP server.

  • Reviewing /etc/nsswitch.conf:

    • This file determines how host name resolution is prioritized.

    • Example order in /etc/nsswitch.conf: hosts: files dns myhostname.

    • This setup means that the system first checks /etc/hosts, then checks DNS, and finally falls back on resolving the host name.

Manipulating Host Name Resolution

  • Editing /etc/hosts:

    • If you edit the /etc/hosts file and add an entry like 192.168.29.141 google.com, it will override the DNS entry when using ping google.com.

    • Therefore, the ping command would resolve to the given local IP instead of the actual Google server.

    • This method can effectively render certain Internet hosts unreachable by creating local overrides in the /etc/hosts file, thus providing a simple and effective trick for network management.