Add DHCP client hook to update hostname. (#235)
* Add DHCP client hook to update hostname. * Remove interface checking * Update hostname in /etc/hosts file
This commit is contained in:
parent
4cd3d31946
commit
793b842d60
@ -240,6 +240,7 @@ iface eth0 inet dhcp
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
sudo cp files/dhcp/rfc3442-classless-routes $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d
|
sudo cp files/dhcp/rfc3442-classless-routes $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d
|
||||||
|
sudo cp files/dhcp/sethostname $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
|
||||||
|
|
||||||
if [ -f sonic_debian_extension.sh ]; then
|
if [ -f sonic_debian_extension.sh ]; then
|
||||||
./sonic_debian_extension.sh $FILESYSTEM_ROOT
|
./sonic_debian_extension.sh $FILESYSTEM_ROOT
|
||||||
|
20
files/dhcp/sethostname
Normal file
20
files/dhcp/sethostname
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# This script is to update hostname of the system.
|
||||||
|
|
||||||
|
if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
|
||||||
|
&& [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
|
||||||
|
then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_host_name=`hostname -s`
|
||||||
|
|
||||||
|
if [ "$current_host_name" != "$new_host_name" ]
|
||||||
|
then
|
||||||
|
echo $new_host_name > /etc/hostname
|
||||||
|
line_to_replace=`grep 127.0.0.1.*$current_host_name /etc/hosts`
|
||||||
|
new_line=`echo $line_to_replace | sed "s/$current_host_name/$new_host_name/"`
|
||||||
|
sed -i "s/$line_to_replace/$new_line/" /etc/hosts
|
||||||
|
|
||||||
|
hostname -F /etc/hostname
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user