User Tools

Site Tools


hostname - set or print name of current host system

The hostname utility prints the name of the current host. The super-user (root) can set the hostname by supplying an argument. For FreeBSD, if you wish to make changes permanent, you'd need also need to edit /etc/rc.conf

For Linux, it will depend on the distro you're using. Latest versions of Ubuntu, CentOS, Debian, Fedora, and so on, will come with systemd, a system and service manager that provides a hostnamectl command to manage hostnames in Linux.

If you're root already, you can change your hostname by typing:

$ hostnamectl set-hostname MY_NEW_HOSTNAME

Otherwise, </code>$ hostnamectl set-hostname MY_NEW_HOSTNAME</code>

For older Linux edit the hostname file, /etc/hostmame

Once this is done, add another record for the hostname in /etc/hosts

For example host1-linux-node

After this, you'd need to execute the following command: /etc/init.d/hostname restart

If you're using CentOS-based system that use init, the hostname is changed by modifying, /etc/sysconfig/network file

Here's the snippet from that file:

$ cat /etc/sysconfig/network


To make changes permament, change the value next to “HOSTNAME” to the one of your desired hostname.

unix_commands/hostname.txt · Last modified: 2023/01/15 06:34 by admin

CIFNet is a leading hosting solution provider, offering a wide range of services including IP bandwidth, co-location, VMware and KVM hosting.
Host Your Site with CIFNet!