Change hostname on Ubuntu without restart
To change the hostname permanently without a restart enter the following command:
hostnamectl set-hostname myhostname
/etc/hostnamecontains name of the machine, as known to applications that run locally.
/etc/hostsand DNS associate names with IP addresses. hostname may be mapped to whichever IP address the machine can access itself, but mapping it to
/etc/hostname: CONTAINS myhostname
/etc/hosts: CONTAINS THE MAPPING:
127.0.0.1 localhost.localdomain localhost myhostname ::1 localhost.localdomain localhost myhostname