Ubuntu

How To Change Hostname on Ubuntu 24.04 LTS

On this short tutorial we will show you how to change hostname with or without restart server on Ubuntu 24.04 LTS operating system. We will use console rather than setting via GUI.

Changing Hostname Without Reboot/Restart

The needs of changing hostname will be critical when we need fast solution to mitigate our business interrupt matter. Sometimes we need the hostname changes without restarting our sever.

Changing the hostname on a server is often necessary in certain situations without having to reboot. Here are some common situations where a hostname change is necessary:

  • Network and Infrastructure Management
    When renaming a server to follow new naming standards within the organization or department.
    When moving a server to a different domain or network and the old hostname no longer conforms to the new rules.
  • Security
    Change the hostname as part of security measures to avoid easy identification by unauthorized parties.
  • Deploy a New Application or Service
    When configuring a new application or service that requires a specific hostname for connectivity or DNS resolution.
  • Alignment with Backup or Monitoring Systems
    If the backup or monitoring system requires a specific hostname for automatic recognition or configuration.

Currently we have a system with hostname as follow :

ramansah@ramansah-VMware-Virtual-Platform:~$ hostnamectl
Static hostname: ramansah-VMware-Virtual-Platform
Icon name: computer-vm
Chassis: vm ๐Ÿ–ด
Machine ID: 92023e00c93348599ae2d71f8f5c6e93
Boot ID: 99c4e585276a4cefa0b2de53cfcb59e7
Virtualization: vmware
Operating System: Ubuntu 24.04 LTS 
Kernel: Linux 6.8.0-31-generic
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00

ubuntu_change_hostname

To change hostname without rebooting on Linux based systems, you can follow these steps:

1. Changing Temporary Hostname

To change the temporary name, we use the hostnamectl command as follows:

$ sudo hostnamectl set-hostname bckinfo
2. Changing Hostname in /etc/hostname

Edit the /etc/hostname file and replace it with the new hostname.

$ sudo vi /etc/hostname

bckinfo
~ 
~ 
~
3. Changing Hostname di /etc/hosts

Edit the /etc/hostname file and replace it with the new hostname.

$ sudo vi /etc/host

27.0.0.1 localhost
##127.0.1.1 ramansah-VMware-Virtual-Platform
127.0.0.1 bckinfo

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
~ 
~ 
~
4. Verify Changes

To verify the hostname changes, we will use hostname and hostnamectl command line.

$ hostname
bckinfo

$ hostnamectl status
Static hostname: bckinfo
Icon name: computer-vm
Chassis: vm ๐Ÿ–ด
Machine ID: 92023e00c93348599ae2d71f8f5c6e93
Boot ID: 99c4e585276a4cefa0b2de53cfcb59e7
Virtualization: vmware
Operating System: Ubuntu 24.04 LTS 
Kernel: Linux 6.8.0-31-generic
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
Firmware Date: Thu 2020-11-12
Firmware Age: 3y 6month 1w 3d

change_hostname_ubuntu_2404

Changing Hostname With Reboot/Restart

There are some situations where a hostname change on a server requires a reboot to ensure that all services and systems fully acknowledge the change. Here are some reasons and situations where a reboot may be necessary.

Specific Operating Systems

Some operating systems or older versions may require a reboot to fully apply hostname changes. Although many modern Linux distributions allow hostname changes without rebooting, some systems such as some versions of Unix or Windows may require a reboot.

Critical Services that Lock Hostname

Some services or applications running on the server may lock the hostname at startup and will not recognize the change until the service is stopped and restarted. In some cases, stopping and restarting these services can disrupt server operation making a reboot a safer and more thorough option.

Complex Network Setup

If the server has complex network settings, such as integration with a dynamic DNS service, VPN, or other advanced network configuration, a hostname change may require a reboot to ensure all network components are reinitialized with the new name.

Compatibility with Scripts and Configurations

Some startup scripts or configurations may only be executed at boot time. If a new hostname is required for this script or configuration to run correctly, then a reboot is required to ensure all system components are using the new hostname.

Conclusion

By following the steps above, you can change the server hostname with or without needing to reboot. This is very helpful in ensuring server availability and uptime are maintained.

(Visited 47 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *