Linux change hostname or system name
This post will guide you how to change your hostname or computer system using the command line under linux operation system. If you are using a ubuntu Linux system, and how to change your hostname or the machine name under command line option.
You can use the HOSTNAME command or HOSTNAMECTL command to acieve the result. You can also use those two commands to set or display the current hostname or domain name of your system. the hostname of your system can be used by other linux programs to identify this machine, such as: networking program.
Display Hostname
you can directly execute the hostname command to get the name of the system under command line option, type the following command:
#hostname
Outputs:
devops-osetc.com
Change Hostname
if you want to change the current hostname of your system, you can also use the hostname command. For example, if you want to set the current hostname as devops-osetc-new.com, type the following command:
#hostname devops-osetc-new.com
Change hostname permanently
if you want to change hostname permanently on your linux system, you need to change the hostname config file /etc/hostname, just do the following steps:
#1 edit the config file /etc/hostname with vi/vim command, type:
#vi /etc/hostname
#2 add new hostname into the config file, just like this line:
devops-osetc-new.com
#3 save and close the config file. then reboot the system.
Note: if you do not want to reboot system, and you need to run the below command:
#/etc/init.d/hostname.sh start
Change hostname using HOSTNAMECTL command
You can also use the hostnamectl command to change or set the hostname of your system under command line option.
Display Current Hostname
if you want to get the current hostname with hostnamectl command, just execute the following command:
#hostnamectl
Change hostname with hostnamectl command
if you want to change the hostname with hostnamectl command , just type the following command:
# hostnamectl set-hostname devops-osetc-new.com
Remove hostname with hostnamectl
if you want to remove the specific hostname and change its as default hostname, just type the following command:
#hostname set-hostname ""