Ubuntu Change Hostname
How to display the current Ubuntu hostname
Simply type the following command:$ hostnamectl
Ubuntu 18.04 LTS change hostname permanently
The procedure to change the computer name on Ubuntu 18.04 LTS:
- Type the hostnamectl command :
sudo hostnamectl set-hostname newNameHere
Delete the old name and setup new name. - Next Edit the /etc/hosts file:
sudo nano /etc/hosts
Replace any occurrence of the existing computer name with your new one. - Reboot the system to changes take effect:
sudo reboot
How to change hostname on Ubuntu 18.04 without a system restart
Let us see current setting just type the following command:$ hostnamectl
Next change hostname from localhost to u1804-nixcraft, enter:$ hostnamectl set-hostname u1804-nixcraft
Verify new changes:$ hostnamectl
Find your public or private IP address by running the ip command:$ ip a
$ ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 40:9f:38:28:f6:b5 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.24/24 brd 192.168.2.255 scope global noprefixroute enp6s0
valid_lft forever preferred_lft forever
inet6 fe80::429f:38ff:fe28:f6b5/64 scope link
valid_lft forever preferred_lft foreverUpdate /etc/hosts file with that IP address such as 192.168.2.24 using a text editor such as vim command/nano command:$ sudo vi /etc/hosts