DEV Community

Randika Madhushan Perera
Randika Madhushan Perera

Posted on

Configuring Host names & Name resolution

1. Changing the System Hostname

We can display the hostname or temporarily modify the systems' fully qualified hostname using the hostname command.

[root@servera ~]# hostname
servera.lab.example.com
Enter fullscreen mode Exit fullscreen mode

The static hostname is normally specified in the /etc/hostname file. To edit the hostname we can use hostnamectl command.

[root@servera ~]# hostname
servera.lab.example.com

[root@servera ~]# hostnamectl set-hostname node1.example.com
node1.example.com
Enter fullscreen mode Exit fullscreen mode

2. Configure Name Resolution

Name resolution, in the context of computer networking, is the process of translating human-readable domain names into IP addresses. This is a fundamental aspect of how the internet works because it allows us to access websites and services using easy-to-remember domain names like "www.example.com" instead of numeric IP addresses like "192.168.1.1."

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.

In case an entry isn't found within the /etc/hosts record, by default the stub resolver tries to see 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 hostname. Both this and the domain should not be set in the same file; if they are, the last instance wins.
  • 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@servera ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain example.com
search example.com
nameserver 172.25.254.254
Enter fullscreen mode Exit fullscreen mode

NetworkManager updates the /etc/resolv.conf file using DNS settings in the connection configuration files. Use the nmcli to modify the connections.

[root@servera ~]# nmcli con mod ID ipv4.dns IP
[root@servera ~]# nmcli con down ID
[root@servera ~]# nmcli con up ID
[root@servera ~]# cat /etc/sysconfig/network-scripts/ifcfg-ID
...output omitted...
DNS1=8.8.8.8
...output omitted...
Enter fullscreen mode Exit fullscreen mode

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@servera ~]# nmcli con mod ID +ipv4.dns IP
Enter fullscreen mode Exit fullscreen mode

3. Testing DNS Name Resolution

hostname command can be used to test DNS connectivity.

[root@servera ~]# host servera.lab.example.com
servera.lab.example.com has address 172.25.254.254
[root@servera ~]# host 172.25.254.254
254.254.25.172.in-addr.arpa domain name pointer servera.lab.example.com.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)