From c2a551d2f655aaaf2853b7d8edc27633707009fc Mon Sep 17 00:00:00 2001 From: Prabhu Date: Wed, 16 Jan 2019 14:45:34 +0530 Subject: [PATCH] Avoid removing localhost entry from /etc/hosts file --- files/image_config/hostname/hostname-config.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/files/image_config/hostname/hostname-config.sh b/files/image_config/hostname/hostname-config.sh index eec7c2f732dc..6cb8f73cf4af 100755 --- a/files/image_config/hostname/hostname-config.sh +++ b/files/image_config/hostname/hostname-config.sh @@ -6,6 +6,11 @@ HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']` echo $HOSTNAME > /etc/hostname hostname -F /etc/hostname -sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts +# Remove the old hostname entry from hosts file. +# But, 'localhost' entry is used by multiple applications. Don't remove it altogether. +if [ $CURRENT_HOSTNAME != "localhost" ] || [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then + sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts +fi + echo "127.0.0.1 $HOSTNAME" >> /etc/hosts