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

Hướng dẫn cấu hình và thiết lập TIG stack để giám sát Network

Trong bài viết trước, Onet đã giới thiệu và hướng dẫn cài đặt TIG stack để giám sát hệ thống. Hôm...
30/12/2020

Arch Linux Package System

Arch Linux is a lean and highly customizable distribution of the Linux operating system, and one of its biggest strengths...
28/12/2020

Hướng dẫn đổi ngôn ngữ mặc định, đổi logo, favicon, độ phân giải video trên Jitsi

Đôi khi, bạn muốn “cá nhân hóa” một chút cho các ứng dụng tự dựng như jitsi, ví dụ...
30/12/2020
Bài Viết

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

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024