Learn how to quickly set a Linux hostname without having to reboot the server.
Long ago, in an operating system far, far away, the act of changing a hostname in Linux required a reboot. This wasn't too big of a deal, especially considering most production machines rarely change hostnames. However, there are times when changing a hostname is advantageous—say in a testing environment, or when a machine has been repurposed for another use.
So there are times when you might find yourself needing to change that hostname. Instead of modifying a file and rebooting the server as we had to do during the early years of Linux, there's a much more efficient way of changing a hostname.
I'm going to show you how that's done.
SEE: 10 free alternatives to Microsoft Word and Excel (TechRepublic download)
If you open a terminal window or log in to the machine in question, you should see the hostname listed after the USERNAME@ entry (where USERNAME is the name of the user you've logged in with). You could also use the command hostname to view the hostname of the machine. So, how do you change that hostname?
With the hostnamectl command. To do this issue the command sudo hostnamectl set-hostname NAME (where NAME is the name of the hostname to be used). Now, if you log out and log back in, you'll see the hostname has changed.
That's it--you've changed the hostname without having to reboot the server. Just make sure that any user who has logged in logs out and logs back in, otherwise the change won't take effect for their session. Also, if you have any host files mapping an IP address to the previous hostname, make sure to edit those. Outside of that, happy hostnaming.
- How to become a software engineer: A cheat sheet (TechRepublic)
- Choosing your Windows 7 exit strategy: Four options (TechRepublic Premium)
- How to back up a local Linux directory to a remote Linux host with rsync (TechRepublic)
- Try out this new Linux exFAT kernel module for improved performance (TechRepublic)
- How to quickly deploy a honeypot with Kali Linux (TechRepublic)
- How to limit bandwidth on Linux to better test your applications (TechRepublic)
- Linux laptops: System76 reveals Intel 10th generation CPUs for its two new models (ZDNet)
- It takes work to keep your data private online. These apps can help (CNET)
- The 10 most important iPhone apps of all time (Download.com)
- Must-read coverage: Programming languages and developer career resources (TechRepublic on Flipboard)