Wednesday, March 25, 2020

How to Change Hostname on Ubuntu 18.04

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

Recent Post

Databricks Delta table merge Example

here's some sample code that demonstrates a merge operation on a Delta table using PySpark:   from pyspark.sql import SparkSession # cre...