In this article you will find more about hostname commands in linux systems. you will learn how to find hostname or how change host name in linux systems.there is some ways to change hostname in centos(linux) systems.

Find Hostname in linux

you can use command below in ssh to find hostname in centos or linux systems

hostname

Change Hostname in linux

To chane your linux server host name you can use this way.

hostname server.sampledomain.com

replace server.sampledomain.com with your hostname

 

Permanent hostname change on Debian systems

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh

/etc/hostname
server

So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:

/etc/init.d/hostname.sh start

to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).

 

Permanent hostname change on RedHat based systems


RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot.

nano /etc/sysconfig/network

the output will be like this you can edit hostname field and save and exit file with CTRL+X.


NETWORKING=yes
HOSTNAME="plain.domainname.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"


the you should reboot your server for changes take effect.

 

Change Hostname in linux- Find hostname in linux