Jump to content

What is the recommended way to change the hostname?


Go to solution Solved by mitu,

Recommended Posts

Posted

Found the actual codes executed in /usr/lib/armbian-config/jobs.sh, when you run

sudo armbian-config

Basically, it updates /etc/hostname, /etc/hosts

Here is my wrapped function:

change_hostname() {
    # modified from /usr/lib/armbian-config/jobs.sh
    # should be OK for debian as well(?)
    local hostname_current=$(cat /etc/hostname)

    if [[ -z $1 ]]; then
        echo "Current hostname: $hostname_current"
    else
        local hostname_new=$1
        sudo sed -i "s/$hostname_current/$hostname_new/g" /etc/hosts
        sudo sed -i "s/$hostname_current/$hostname_new/g" /etc/hostname
        # Temporarily change the hostname for the current session
        sudo hostname "$hostname_new"
        sudo systemctl restart systemd-logind.service
        echo "Logout to make effective the new hostname: $hostname_new"
    fi
}

 

Posted
13 hours ago, arman said:
 sudo systemctl restart systemd-logind.service

 

Will log you out automatically, at least when running desktop.

 

In case one is running Google Chrome, this will lock it out ;) This 10 years bug is still valid:
https://askubuntu.com/questions/476918/google-chrome-wont-start-after-changing-hostname

 

BTW. We are switching to armbian-config new generation soon and here this is done this way:

https://github.com/armbian/configng/blob/main/lib/armbian-configng/config.ng.system.sh#L33-L38

If you have ideas for improvements, welcome.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines