Monday 22 September 2008

Change / Create HOST NAME

Checking your Linux host name
First, see if your host name is set correclty using the following commands:
#uname -n
#hostname -a
#hostname -s
#hostname -d
#hostname -f
#hostname
If the above commands return correctly with no errors then all may be well;
however, you may want to read on to verify that all settings are correct.
Normally we will set the hostname of a system during the installation process.
Change the hostname on a running Linux system
On any Linux system you can change its hostname with the command ‘hostname‘.
#hostname
without any parameter it will output the current hostname of the system.
#hostname –fqd
it will output the fully qualified domain name (or FQDN) of the system.
#hostname NEW_NAME
will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will
be rebooted (because at system boot it will set this from some particular file configurations - see bellow how to set this
permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.
Permanent hostname change on Debian based Linux 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
#cat /etc/hostname
debianadmin
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 startto 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).
If you want more details check hostname man page
Use sysctl to change the hostname
use sysctl to change the variable kernel.hostname:
Use:
#sysctl kernel.hostname
to read the current hostname, and
#sysctl kernel.hostname=NEW_HOSTNAME
to change it.

No comments: