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
}