Change Hostname for Linux Distros Without Restart Your Machine

28/12/2020
Chưa phân loại

If you have ever wanted to find out how you can change hostname of your linux machine, then this tut is for you. So in this tutorial I will show you how you can rename / change your Linux machine hostname without having to reboot for it to take effect. The method that will be shown here will work for the following Linux distros “Ubuntu 16.10, Ubuntu 16.04, Ubuntu 14.04, Linux Mint, CentOS 7, Fedora 21, RHEL 7.

Ubuntu 16.10, Ubuntu 16.04, Ubuntu 14.04, Linux Mint

Change Hostname Temporary

  • To change hostname temporary, run following command. Note this would only apply while machine is still on, but when you reboot your machine, hostname will revert back to preview name

sudo hostname NEW_HOSTNAME_HERE

Change Hostname Permanently

  • Edit the following files “/etc/hosts” & “/etc/hostname“. First of all, lets make sure “gksu” is installed on your machine by running following command
sudo apt-get install gksu
  • Edit both files with following command
gksudo gedit /etc/hosts /etc/hostname
  • In the “hosts” file, replace the existing hostname with the new one. Same goes for the second file “hostname“. Note both names MUST be exact same. Save both changes and close files

  • Since this tut is about making this changes without restarting the machine, so for the name to take effect, run the following command
systemctl restart systemd-logind.service

CentOS 7, RHEL 7, Fedora 21 and above

There is more than one method of changing the hostname of CentOS, Fedora and RHEL machines but for this tut, we will use a tool called “hostnamectl”. hostnamectl is a command tool that can be used to all 3 class of host name “pretty”, “transcient” and “static” hostnames.

What is Pretty, Transient and Static Hostnames

  • Pretty hostname is a high-level hostname which can include special characters (e.g. Linuxhint’s Laptop)
  • Transient hostnames are once obtained by network configuration (e.g. DHCP)
  • While Static is the conventional hostname most server admins are used to. It is used to initialize the kernel hostname at boot

Using hostnamectl

  • To replace all hostname at once, run the following command. Note replace linuxhintOS with your new hostname
hostnamectl set-hostname linuxhintOS
  • To each hostname class, run the following command.
hostnamectl set-hostname linuxhintOS --<option>

where <option> can be replaced with either “pretty”, or “transcient” or “Static”, as shown below

hostnamectl set-hostname linuxhintOS --pretty
  • Next relaunch the terminal session (Putty or console) and check the hostname
hostnamectl status

Please feel free to comment if you run into any issues or have a better setup so we share and update our post. Thanks…

ONET 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, ONET 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

Best 25 Ubuntu News Websites and Blogs

Linux is an open-source operating system and Ubuntu is one of its very popular distros which is rapidly increasing its user...
29/12/2020

Cách tạo Cron Jobs trên Hosting Cpanel

Cron Jobs là gì? Là chức năng dùng để thực thi định kì lệnh nào đó trong một khoảng thời gian...
23/12/2020

Install PDFtk on Ubuntu

PDF is an integral part of our everyday life. It’s a document format that’s trusted by every single platform. Often...
29/12/2020
Bài Viết

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

Check proxy trên trang nào chuẩn nhất❓
01/11/2023

Thuê Proxy chạy Google Ads / Cần chú ý gì khi chọn proxy và email chạy G.G ads?
12/10/2023

Thuê proxy 4G ở đâu uy tín, giá rẻ, chất lượng?
05/10/2023

Vì sao cần thuê proxy xoay? Địa chỉ cung cấp proxy xoay uy tín
05/10/2023

Thuê proxy v6 kéo view Youtube ở đâu uy tín, chất lượng?
05/10/2023