• Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
  • Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
Home»Distros»Ubuntu»How To Change Hostname On Ubuntu

How To Change Hostname On Ubuntu

Anup ThapaBy Anup ThapaMarch 2, 2023 Ubuntu 3 Mins Read

The hostname is a name that identifies a device on a network. Ubuntu has some basic requirements when it comes to hostname validity.

It can be 253 characters long at most, and you may only use letters, numbers, or hyphens. Assuming these conditions are fulfilled, changing your hostname on Ubuntu is very easy.

System Settings

The first way to change your hostname is from the control center.

  1. Search and open ‘About’ from the Activities overview.
    ubuntu about system
  2. Click on the Device Name field. Set the new hostname here and press Rename. 
    change ubuntu device name

Hostnamectl

Hostnamectl is the standard tool for managing the system hostname and related settings on Ubuntu. We’ll use it to set anupspc as the new hostname. By default, this will alter the Static, Transient, and Pretty hostnames.

hostnamectl set-hostname anupspc

The static hostname is the standard hostname that we just set. It’s stored in the /etc/hostname file. The pretty hostname has fewer naming restrictions (UTF-8) as it’s intended to be read by users. The transient hostname is usually the same as static too, but it can change based on your network configuration (due to DHCP and mDNS servers).

If you want to set any of these individually, you can use the --static, --transient, or --pretty options. For instance, let’s set anup’spc as the pretty hostname for better readability. 

hostnamectl set-hostname --pretty “anup’spc” 

You can verify the change with hostnamectl or you can specify the exact hostname type like so

hostnamectl --pretty

Network Manager

NetworkManager’s CLI tools (nmtui/nmcli) also work fine for changing the static hostname. Nmcli is very straightforward.

sudo nmcli general hostname anupspc

If you want to use nmtui instead, start it with

sudo nmtui

Select Set System Hostname and press Enter. Set the new hostname and press Ok. Then, press Esc or select Quit to exit nmtui.

Edit Config Files

You can also directly modify the /etc/hostname and /etc/hosts files to change your hostname. 

sudo nano /etc/hostname

Set the new hostname here and write out the changes.

sudo nano /etc/hosts

Once again, replace the old hostname here and save the changes.

The downside to this method is that such configs are supposed to be modified using the utilities shown earlier. Due to this, NetworkManager doesn’t pick up manual changes to the config files until you restart.

Hostname

If you only need to change the hostname temporarily, you can use the hostname command like so  

sudo hostname anupspc

This will set anupspc as the transient hostname for the current session. Your system hostname will revert to the previous name upon restarting.

Anup Thapa
  • LinkedIn

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. At LinuxStart, Anup is an integral part of our editorial team. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys experimenting with different Linux distros and reading up on things like networking and virtualization.

Leave A Reply Cancel Reply

Table of Contents
  • System Settings
  • Hostnamectl
  • Network Manager
  • Edit Config Files
  • Hostname
Linux Start
Guides

What is the Linux Kernel?

The Linux Kernel is the core of the Linux operating system and is central to…

How To Install Linux Mint

How To Install Linux on VirtualBox

Getting Started with Linux

How to Install Linux

10 Best Linux Distros of 2023

Which Linux Distro Should You Choose? A Complete Guide to Help You Decide

© 2023 LinuxStart.com

Type above and press Enter to search. Press Esc to cancel.