You need to use the hostnamectl command to see or set the Ubuntu 18.04 LTS system’s host name. The host name or computer name is usually at system startup in /etc/hostname file. Open the terminal application and type the following commands to set or change hostname or computer name on Ubuntu.
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 forever
Update /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
OR
$ sudo nano /etc/hosts
Update/append:
192.168.2.24 u1804-nixcraft
Make sure you replace any occurrence of the old computer name with your new one too. Save and close the file in vim.
Conclusion
You learned how to change hostname permanently when using Ubuntu 18.04 LTS as per your needs.
- Ubuntu Linux Change Hostname (computer name)
- Debian Linux: Change Hostname / Computer Name Permanently
- Linux change my hostname / computer system name
- Linux Change Hostname
- RHEL / Centos Linux 7: Change and Set Hostname Command
- OpenBSD Change Hostname
- CentOS Linux 5/6 Change Hostname Command
- Linux setting hostname and domain name of my server
- FreeBSD Change Hostname without reboot
- SuSe Linux Change Hostname without reboot
- How to set the hostname on Fedora Linux
- Ubuntu 18.04 LTS change hostname permanently
- Ubuntu set hostname permanently (computer name) command
- OpenSUSE Linux set hostname permanently (computer name) command
- RHEL 8 Linux set hostname permanently (computer name) command
- CentOS 8 Linux set hostname permanently (computer name) command
- Ubuntu 20.04 LTS set hostname permanently (computer name) command
- Set / Change FQDN on Ubuntu 20.04 LTS
- Alpine Linux - Setting system hostname
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
This article is F****N FALSE! FIX THIS SHIT AND GET THE FACTS STRAIGHT. Anytime after reboot it STILL DEFAULTS TO THE SAME DAM HOSTNAME!
First, cursing doesn’t work. Are you using cloud server like AWS? Are you using Ubuntu Linux? There might be settings in /etc/cloud/cloud.cfg file and Append the following line to the same file:
preserve_hostname: true