"# Auto-generated hostname. Please do not remove this comment." Why not?

In CentOS (but possibly other distros), /etc/hosts has the following comment:

# Auto-generated hostname. Please do not remove this comment.

Since the comment itself asks not to be removed, it seems as though it serves a purpose other than just informational. Perhaps some package checks for its existence.

Googling for this exact comment shows that many hosts files contain it, although none of the results explain the origin of the comment itself.


Edit: Another question that mentions this comment states that it is somehow the cause of the hosts file being overwritten upon reboot. This is not the case for me, as my hosts file already has custom entries and has never been arbitrarily overwritten. The only machine I have with this comment is in a production environment, so I'm unable to reboot and or remove the comment for testing.

That question is here: Why is my hosts file reseting on reboot?


What is the reason for this comment, and are there consequences for removing it?


Let's ask Debian Code Search about this text. Result 1 of 1:

vzctl_4.9.4-6/etc/dists/scripts/functions

local host="$2"
local ip="$3"
local comm='# Auto-generated hostname. Please do not remove this comment.'
[ -f "${cfg}" ] || touch ${cfg}

appears to be related to the vzctl package, which is part of the OpenVZ/Virtuozzo container "virtualization" system.

Within this file, there's an awk script which dynamically rewrites /etc/hosts to make sure the system's own local hostname will remain resolve-able if it is changed with vzctl set --hostname. It looks for this comment ($0 == comm) in order to… well, I'm not entirely sure what.

If you do not use vzctl, there should be no problems with removing the header.

Side note: Although editing /etc/hosts to match the system hostname has always been necessary, even outside of OpenVZ, now it is slowly becoming irrelevant thanks to nss-myhostname and/or systemd-resolved being able to produce the same answer on the fly.