Thursday, November 30, 2023

How To: Update your hosts file

Firstly the /etc/hosts file is the primary resource for name resolution without DNS. The /etc/hosts file has priority over the DNS in the process of addressing network nodes. This is a table lookup file of host names and IP addresses. Our host name as well as others may be stored, in this file which we may edit.

The general file format should look like the following, and can include multiple host names for one IP:


       # The following lines are desirable for IPv4 capable hosts
       127.0.0.1       localhost

       # 127.0.1.1 is often used for the FQDN of the machine
       127.0.1.1       thishost.example.org   thishost
       192.168.1.10    foo.example.org        foo
       192.168.1.13    bar.example.org        bar

       # The following lines are desirable for IPv6 capable hosts
       ::1             localhost ip6-localhost ip6-loopback
       ff02::1         ip6-allnodes
       ff02::2         ip6-allrouters


So we use our favorite text editor, and update this file to fully implement any recent network updates.
We may also use the /etc/hosts file to include address changes to our LAN and implement network resolution restrictions.

If we remove a host name from /etc/hosts, we also will potentially render a service inoperable due to a defunct host name. Therefore each administrator may consider system integrity, with respect to any installed software (i.e. software may not start properly, without a valid host name).

You can also alter the order of name resolution, in the case you find /etc/hosts having priority to be inconvenient. The /etc/nsswitch.conf file can be edited, and should contain an entry like the following:

        hosts:          files dns

Given these options, we can take a flexible approach to managing the systems host name resolution.