[email protected]Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 21, 2023

How to Set or Change Hostname in Linux

How To Set Or Change Hostname In Linux

This tutorial will walk you through the process of changing the hostname in Linux without the need of restarting the system. The instructions should work on any modern Linux distribution that uses systemd.

By default, the system hostname is set during the installation process, or if you are creating a virtual machine it is dynamically assigned to the instance at startup, but there are situations when you need to change it.

 

What is Hostname

A hostname is a label assigned to a machine that identifies the machine on the network. Each device in the network should have a unique hostname.

 

Displaying the Current Hostname

On Linux systems using systemd, the hostnamectl command can be used to query and change the hostname and related settings on a given machine.

To view the current hostname, invoke the hostnamectl command without any arguments:

hostnamectl

The system hostname is highlighted in the image below:

Changing the Hostname

To change the hostname invoke the hostnamectl command with the set-hostname argument followed by the new hostname. Only the root or a user with sudo privileges can change the system hostname.

For example, to change the system hostname to mail.nexonhost.com, you would use the following command:

sudo hostnamectl set-hostname mail.nexonhost.com

The hostnamectl command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.

Finally, to verify that the hostname was successfully changed, once again use the hostnamectl command:

hostnamectl

The new system hostname and some additional system information such as the kernel version will be displayed on the terminal.

   Static hostname: mail.nexonhost.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 114054dc5a87478f99adbbed6027eea0
           Boot ID: 93edf5b522e04224894f7e46aa16b926
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.81.1.el7.x86_64
      Architecture: x86-64

 

Conclusion

In this tutorial, we have shown you how to change the hostname of your Linux system. Depending on your Linux distribution and the virtualization type, additional steps may be required to complete the process.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Mon – Fri 9:00AM – 5:00PM