Change hostname in systemd
After systemd came into the picture of Linux
managing the machine and it's services became more easier.
Also due to this in every Linux distro it's commands
are much similar to manage the machine and it's services.
To apply the changes in hostname first need to be super user that is root.
As this is a system change so prvilege of super user is require.
Below is the command to become root user
$ su -
$ sudo -i
To change the hostname use the below command of systemd.
# hostnamectl set-hostname [desire hostname]
# hostnamectl set-hostname linuxmachine
Or you may use sudo tool with above command as shown in below example.
Below one line command can also be useful in bash scripting.
$ sudo hostnamectl set-hostname [desire hostname]
$ sudo hostnamectl set-hostname linuxmachine
Use below command to verify the hostname changed sucessfully in systemd.
There is no require to reboot the machine to apply changes done in hostname.
To get the effect of the change in hostname, user need to login again.
Designed by SanjuD(@ngineerbabu)