Display the Current Hostname
To view the current hostname, enter the following command:
hostnamectl
As you can see in the image above, the current hostname is set to
ubuntu1804.localdomain
.Change the Hostname
The following steps outline how to change the hostname in Ubuntu 18.04.
1. Change the hostname using hostnamectl
.
In Ubuntu 18.04 we can change the system hostname and related settings using the command
hostnamectl
.
For example, to change the system static hostname to nagaraju, you would use the following command:
sudo hostnamectl set-hostname nagaraju
The
hostnamectl
command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.
2. Edit the /etc/hosts
file.
Open the
/etc/hosts
file and change the old hostname to the new one.
/etc/hosts
127.0.0.1 localhost
127.0.0.1 nagaraju
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
No comments:
Post a Comment