The /etc/hosts file is not populated with the hostname and IP in Red Hat Enterprise Linux 6

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6.1 or later

  • Red Hat Enterprise Linux 6.0 (*1)

Issue

  • The /etc/hosts file is missing the hostname :

    # more /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
  • On Red Hat Enterprise Linux 5 the /etc/hosts file is :

    $ more /etc/hosts
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1        localhost.localdomain localhost
    ::1              localhost6.localdomain6 localhost6
    10.211.50.34        vm.it.domain.com vm-it-domain
    

Resolution

  • Let us take both network scenarios (static and dhcp) of a system on RHEL 5 and RHEL 6 :

1. First Scenario - Static network configuration :
Both, RHEL 5 and RHEL 6 do not add the assigned ip/hostname, but RHEL 5 adds the hostname to the loopback  :

  • RHEL5 :- The hostname is appended to the the loopback address :

    # Do not remove the following line, or various programs 
    # that require network functionality will fail. 
    127.0.0.1   localhost.localdomain   localhost    vm43.example.com
    ::1         localhost6.localdomain6 localhost6
    
  • RHEL 6 : No hostname is added :

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 
    
  • This change is due to the bz here : https://bugzilla.redhat.com/show_bug.cgi?id=530343

2. Second scenario - DHCP configuration :

  • RHEL 5 : The public ip and hostname is added to /etc/hosts :

    # cat /etc/hosts
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1          localhost.localdomain localhost
    ::1                  localhost6.localdomain6 localhost6
    10.65.210.86          dhcp210-86.example.com dhcp210-86
    
  • RHEL 6.0 : The public ip and hostname is also added :

    # cat /etc/hosts
    10.65.211.39     vm39.example.com     vm39     # Added by NetworkManager
    127.0.0.1     localhost.localdomain     localhost
    ::1             vm39.example.com     vm39     localhost6.localdomain6     localhost6
    
  • (*1) RHEL 6.0 : The public ip and hostname is not added to /etc/hosts - (dhcp installation with non-kickstart) :

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    
  • In RHEL 6.0, this is done by NetworkManager and as the IP changes NM adds the appropriate entry. Till this point the behavior is consistent with RHEL 5. But, in RHEL 6.1 this was changed as per BZ : https://bugzilla.redhat.com/show_bug.cgi?id=668830

  • Therefore in RHEL 6.1 Network Manager does not touch /etc/hosts file at all and only adds to hostname to /etc/sysconfig/network

Root Cause

  • Check :
    • https://bugzilla.redhat.com/show_bug.cgi?id=530343
    • https://bugzilla.redhat.com/show_bug.cgi?id=668830

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments