Skip to content

Commit

Permalink
Avoid duplicate entries for the metadata server in /etc/hosts
Browse files Browse the repository at this point in the history
In cases where the metadata server /etc/hosts entry was not added by the
guest environment scripts there will be no "# Added by Google" marker. As
such the script will add a second reference to the metadata if it already
exists. We should only have 1 entry. Respect the already existing entry and
do not add a second entry.
  • Loading branch information
rjschwei committed Dec 13, 2024
1 parent bd7ebcc commit 1f9e9f2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/usr/bin/google_set_hostname
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ if [ -n "$new_host_name" ] && [ -n "$new_ip_address" ]; then
echo "${new_ip_address} ${new_host_name} ${new_host_name%%.*} # Added by Google" >> /etc/hosts
fi

# Add an entry for reaching the metadata server in /etc/hosts.
echo "169.254.169.254 metadata.google.internal # Added by Google" >> /etc/hosts
# Add an entry for reaching the metadata server in /etc/hosts.
has_metadata_entry=$(grep metadata.google.internal /etc/hosts)
if [ -z "$has_metadata_entry" ]; then
echo "169.254.169.254 metadata.google.internal # Added by Google" >> /etc/hosts
fi
fi

# /sbin/dhclient-scripts in both ubuntu and centos have some problems for us:
Expand Down

0 comments on commit 1f9e9f2

Please sign in to comment.