How to change System Hostname in Ubuntu Linux. How to change the hostname of a Linux system without restarting. On Ubuntu, how to change Hostname via Command Line. Learn how to use hostname command in Ubuntu Linux to change Linux computer name.
Change System Hostname Without Restarting
Hostname command is used to display the system’s DNS name, and to display or set its hostname or NIS domain name. When hostname command is executed without any parameters, it displays the active hostname of the Linux Ubuntu system
$ hostname
If you want to change or set hostname of your Linux system, simply run:
$ hostname NEWNAME
Replace the NEWNAME with the desired hostname. When the anove command in executed it will immediately change the hostname of the system.
Please Note: It will not change the hostname permanently. It is only temporary and the original hostname will be restored after the next system restart.
Change System Hostname Permanently
If you want to change the system hostname permanently, you can use hostnamectl set-hostname command. The set-hostname command can be used in the following format:
$ sudo hostnamectl set-hostname NEW_HOSTNAME
hostnamectl
hostnamectl may be used to query and change the system hostname and related settings. This tool distinguishes three different hostnames: the high-level “pretty” hostname which might include all kinds of special characters (e.g. “Lennart’s Laptop”), the static hostname which is used to initialize the kernel hostname at boot (e.g. “lennarts-laptop”), and the transient hostname which is a fallback value received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.
Note that the pretty hostname has little restrictions on the characters used, while the static and transient hostnames are limited to the usually accepted characters of Internet domain names. The static hostname is stored in /etc/hostname, see hostname for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see machine-info.
hostname
hostname – show or set the system’s host name
Usage:
hostname [-a|–alias] [-d|–domain] [-f|–fqdn|–long] [-A|–all-fqdns] [-i|–ip-address] [-I|–all-ip-addresses] [-s|–short] [-y|–yp|–nis]
hostname [-b|–boot] [-F|–file filename] [hostname]
hostname [-h|–help] [-V|–version]
hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name hostname display host name
{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name
dnsdomainname display dns domain name
hostname -V|–version|-h|–help print info and exit
Options:
-a, –alias alias names
-A, –all-fqdns all long host names (FQDNs)
-b, –boot set default hostname if none available
-d, –domain DNS domain name
-f, –fqdn, –long long host name (FQDN)
-F, –file read host name or NIS domain name from given file
-i, –ip-address addresses for the host name
-I, –all-ip-addresses all addresses for the host
-s, –short short host name
-y, –yp, –nis NIS/YP domain name