Issue #1240: Improved handling of /etc/hosts updates by ensure_hostname_in_hosts