Rocky-linux 10 /etc/hosts not updating after applying template

I am running a VPS at ovhCloud. New install of Rocky-10. I need to update my /etc/hosts file permanantly. To do so I edited the /etc/cloud/templates/hosts.redhat.tmp1 file and rebooted. The changes did not happen to the /etc/hosts file. I cannot figure out why. Thanks for your help.

The changes are the last two lines of the ffile.

The following lines are desirable for IPv4 capable hosts

127.0.0.1 {{fqdn}} {{hostname}}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

The following lines are desirable for IPv6 capable hosts

::1 {{fqdn}} {{hostname}}
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
127.0.0.1 ovh1 ovh1
127.0.1.1 ovh1.localdomain ovh1

ovh1 is my host name.

I’m probably missing something, but why wouldn’t you just update the /etc/hosts file directly instead of going through a whole other song and dance routine?

An edit to /etc/hosts will take effect immediately and not require any reboot, unless you’re using an application or service that caches dns or hostname data, but those you can just individually restart if needed.

I did what you suggested but upon reboot the cloud-init rewites /etc/hosts . That is why I have to use the file I mentioned previously. Thanks for checking into this. I appreciate it.

Make your changes to /etc/hosts, and then do:

chattr +i /etc/hosts

it then makes the file immutable to changes. I do this at OVH with my /etc/resolv.conf because they constantly overwrite it despite me trying to get cloudinit to stop doing it.

1 Like

Thanks for your help. I tried to sudo vi /etc/hosts to make the changes and my passwd doesn’t work. So I log into the console as root and change my passwd to my original for my user name and no problem. ssh into my home directory and sudo doesn’t work again. Go back to my console at OVH and login as my user no problem. Made sure my user name was tied to group wheel and tried sudo again it wouldn’t take my passwd. I am going to add my username to visudo and see if that helps. When I get this working I will set my /etc/hosts. Thanks for your help. Sorry for the rant.

I was able to perform everything from the console and the /etc/hosts file is set now. I will check the forum to see if anyone else had this new problem after sshing into their VPS.

For sudo you need to be in the wheel group. Which you found out anyway :slight_smile: otherwise su and root password.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.