Skip to content
Snippets Groups Projects

set-hostname

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adphi
    Edited
    set-hostname.sh 235 B
    #!/usr/bin/env bash
    set -e
    if [[ -n "$1" ]]; then
        hostname=$(hostname)
        sudo sed -i "s/$hostname/$1/g" /etc/hosts
        sudo hostnamectl set-hostname $1
        sudo netplan apply
    else
        echo "no new hostname provided"
        exit 1
    fi
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment