This is a POB recipe to change the host name in Ubuntu (and probably other non Debian systems). I have tested this to remotely change machine names through Remoto-IT.
#!/bin/bash -e # common/change-hostname.sh hostname=$1 USAGE="Usage: `basename $0`Now you can run it to change your hostname (I use remoto-it to deploy it remotely):" if [ $# -ne "1" ] then echo $USAGE exit 1 fi #It is mandatory to provide an FQDN which at the minimum is a subdomain address if [[ ! "$hostname" =~ ^.*\..*\..*$ ]] then echo $USAGE exit 1 fi #bash substring removal short=${hostname%%.*} sed -i "/$short/d" /etc/hosts bash -c "echo '127.0.0.1 $hostname $short' >> /etc/hosts" echo $short > /etc/hostname hostname -F /etc/hostname
common/change-hostname.sh myhost.sample.comIn your remote host the below commands should correctly output the short name and the FQDN depending on the flags passed:
$ hostname myhost $ hostname -f myhost.sample.com
No comments:
Post a Comment