diff --git a/files/image_config/hostname/hostname-config.sh b/files/image_config/hostname/hostname-config.sh index e9f7fc122709..c2a4f1e546ce 100755 --- a/files/image_config/hostname/hostname-config.sh +++ b/files/image_config/hostname/hostname-config.sh @@ -3,6 +3,11 @@ CURRENT_HOSTNAME=`hostname` HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']` +if [ -z "$HOSTNAME" ] ; then + echo "Missing hostname in the config file, setting to default 'sonic'" + HOSTNAME='sonic' +fi + echo $HOSTNAME > /etc/hostname hostname -F /etc/hostname