How to Set a New Hostname for your Linux System

Chưa phân loại
We all know that computers over a local area network are identified by IP addressed. Instead of expecting others to remember your IP, you can share with them your computer name which is also called a hostname. A hostname lets other users access your system locally by remembering a more user-friendly form of identification. This is exactly how you access web pages on the Internet by just remembering URLs instead of the Numeric IP of a web-server. In this article, we will tell you how you can set a new hostname for your Linux system through the command line and GUI.

We have run the commands and processes mentioned in this article on a Debian 10 Buster system but you can easily replicate them on most Linux distros.

Changing the Hostname through the Linux UI

The Linux UI can only be used to change what you can call a pretty hostname. This form of hostname is a user-friendly free-form computer name that is mostly used in the UI environments. Contrary to that, a static hostname is the traditional computer name that is set by the user in the /etc/hostname and /etc/hosts file.

The pretty hostname can be changed through your system’s Settings utility. There are two ways in which you can access the system Settings.

Access the Application Launcher through the Super/Windows key and then enter the keywords ‘settings’ in the search bar as follows:

Click the downward arrow in the top panel of the Debian/Ubuntu desktop and then click on the ‘settings’ icon from the following drop-down menu:

In the Settings utility, select the Details tab from the left panel and then select the About tab on it to open the About settings view. This is how the view looks like:

The Device name that you see on this view is the pretty hostname of your computer. You can change this name to a new one by simply editing the Device name text box. As soon as you enter a new name, your system will recognize it as the new pretty hostname of your system.

Tip: One easy and quick  way to access the “About” settings is to enter the keyword ‘device’ in the Application Launcher as follows:

Follow the rest of the article in order to learn how you can change the static hostname of your Linux system, both temporarily and permanently.

Changing the Hostname through the Command Line

Through the command line, you get a lot more power on Linux in order to make detailed system configurations. In order to launch the default command line application on Linux Debian and Ubuntu, open the Application Launcher and enter the ‘Terminal’ keywords as follows:

As the Terminal opens, you can change the static hostname through the following two ways:

  • Change the hostname manually through the /etc/hostname and /etc/hosts file
  • Change the hostname using the hostnamectl command

Change the hostname manually through the /etc/hostname and /etc/hosts file

The hostname command is the easiest way to change the hostname. However, the change is only temporary and the hostname changes to its previous value when you restart the system. Nevertheless, we will explain how you can use this command. Enter the following command to fetch your current hostname:

$ hostname

You can then use the following command as sudo, in order to set a new temporary hostname.

$ sudo hostname “new-hostname”

Please note that only an authorized user can change static hostnames on Linux.


$ sudo hostname debian-linux

In the above example, I changed the hostname and then verified the change through the hostname command.

In order to permanently change the hostname, that stays the same even after restart, please follow these steps:

Open the /etc/hostname file in one of the available text editors. For example, we used the nano editor to open the file as follows:

$ sudo nano /etc/hostname

Change the hostname to the one you wish and then hit Ctrl+x. This will ask you if you want to save the changes. Enter Y and the changes will be saved to the hostname file.

The next step is to change the /etc/hosts file in a similar manner. Open the file as follows:

$ sudo nano /etc/hosts

Then, set the new static hostname that is listed against the IP: and then save the file.

Now when you restart your system, the new static hostname will be set which will not revert back on a system restart.

Change the hostname using the hostnamectl command

The systemd utility on Linux is the most efficient method to change both static and pretty hostnames. If systemd is not installed on your system, use the following command to install it:

$ sudo apt-get install systemd

The hostnamectl command from the systemd utility lists the following information about your system:

You can use it as follows to change the pretty hostname:

$ sudo hostnamectl –pretty “pretty-hostname”

And the following commands to set a static hostname:

$ sudo hostnamectl –static “static-hostname”


$ sudo hostnamectl –static debian-linux


$ sudo hostnamectl set-hostname “static-hostname”


$ sudo hostnamectl set-hostname debian-linux

The change can be verified by running the hostnamectl command again:

As the pretty hostname is the same as the static hostname, the GUI will show the device name as the new hostname we have set:

These were some of the ways through which you can efficiently change the pretty and static hostnames of your Linux system. As an administrator, you can use any method that suits your needs and gives a new and more customized identity to your system.

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to install Stellarium 0.16 – A 3D Planetarium Software on Linux

Stellarium 0.16 recently released, is a free open source planetarium app that enables you to have a realistic view of the...

[Zabbix] Giám sát Cisco Switch – SNMP

Khi nhắc tới các thiết bị network hẳn ai cũng biết tới Cisco. Thiết bị network trong hệ thống...

How to install Eclipse in Ubuntu & Linux Mint with Ease

This is a work-through on how to install Eclipse in Ubuntu desktop. Eclipse Neon is the most recent release from the Eclipse...
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019

How to Update Ubuntu Linux

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu

Hướng dẫn cài đặt Apache CloudStack

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader